PHP header的一些用法

<?php
//PHP header()函数用法
/*** Function: PHP header() examples (PHP)
*/// fix 404 pages:
header('HTTP/1.1 200 OK');// set 404 header:
header('HTTP/1.1 404 Not Found');// set Moved Permanently header (good for redrictions)
// use with location header
header('HTTP/1.1 301 Moved Permanently');// redirect to a new location:
header('Location: http://www.example.org/');// redrict with delay:
header('Refresh: 10; url=http://www.example.org/');
print 'You will be redirected in 10 seconds';// you could also use the HTML syntax:// <meta http-equiv="refresh" content="10;http://www.example.org/ />// override X-Powered-By: PHP:
header('X-Powered-By: PHP/4.4.0');
header('X-Powered-By: Brain/0.6b');// content language (en = English)
header('Content-language: en');// last modified (good for caching)
$time = time() - 60; // or filemtime($fn), etc
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');// header for telling the browser that the content
// did not get changed
header('HTTP/1.1 304 Not Modified');// set content length (good for caching):
header('Content-Length: 1234');// Headers for an download:
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.zip"');
header('Content-Transfer-Encoding: binary');// load the file to send:readfile('example.zip');
// Disable caching of the current document:
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
// Date in the pastheader('Pragma: no-cache');
// set content type:
header('Content-Type: text/html; charset=iso-8859-1');
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: text/plain');// plain text file
header('Content-Type: image/jpeg');// JPG picture
header('Content-Type: application/zip');// ZIP file
header('Content-Type: application/pdf');// PDF file
header('Content-Type: audio/mpeg');// Audio MPEG (MP3,…) file
header('Content-Type: application/x-shockwave-flash');// Flash animation// show sign in box
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');
print 'Text that will be displayed if the user hits cancel or ';
print 'enters wrong login data';/*------------的例子用于下载文件用-------------------*/function dl_file($file){//First, see if the file existsif (!is_file($file)) { die("404 File not found!"); }//Gather relevent info about file$len = filesize($file);$filename = basename($file);$file_extension = strtolower(substr(strrchr($filename,"."),1));//This will set the Content-Type to the appropriate setting for the fileswitch( $file_extension ) {case "pdf": $ctype="application/pdf"; break;case "exe": $ctype="application/octet-stream"; break;case "zip": $ctype="application/zip"; break;case "doc": $ctype="application/msword"; break;case "xls": $ctype="application/vnd.ms-excel"; break;case "ppt": $ctype="application/vnd.ms-powerpoint"; break;case "gif": $ctype="image/gif"; break;case "png": $ctype="image/png"; break;case "jpeg":case "jpg": $ctype="image/jpg"; break;case "mp3": $ctype="audio/mpeg"; break;case "wav": $ctype="audio/x-wav"; break;case "mpeg":case "mpg":case "mpe": $ctype="video/mpeg"; break;case "mov": $ctype="video/quicktime"; break;case "avi": $ctype="video/x-msvideo"; break;//The following are for extensions that shouldn't be downloaded (sensitive stuff, like php files)case "php":case "htm":case "html":case "txt": die("Cannot be used for ". $file_extension ." files!"); break;default: $ctype="application/force-download";}//Begin writing headersheader("Pragma: public");header("Expires: 0");header("Cache-Control: must-revalidate, post-check=0, pre-check=0");header("Cache-Control: public");header("Content-Description: File Transfer");//Use the switch-generated Content-Typeheader("Content-Type: $ctype");//Force the download$header="Content-Disposition: attachment; filename=".$filename.";";header($header );header("Content-Transfer-Encoding: binary");header("Content-Length: ".$len);@readfile($file);exit;}

 

/**********下載2************/
if (!@fopen($file,"r")) { die("404 File not found!"); }
header
('Expires: 0'); header('Pragma: public'); header('Connection: close'); header('Cache-Control: no-cache,must-revalidate'); header('Content-Transfer-Encoding: binary'); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file));
//header('Content-Length: ' . filesize($file)); @readfile($file);

 

转载于:https://www.cnblogs.com/helin/archive/2013/01/07/2850271.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/409249.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

手游服务器验证,手游登录流程

接入第三方渠道后的手游登录流程一、客户端登录渠道流程&#xff1a;1.玩家从客户端输入user_name和password2.登录成功后&#xff0c;返回一个token传入&#xff1a;app_id、app_key、user_name、password返回&#xff1a;token说明&#xff1a;app_id、app_key是由游戏制作方…

区块链是大数据生态圈技术之一_区块链技术再发力,携手智能制造构建产业生态圈...

原标题&#xff1a;区块链技术再发力&#xff0c;携手智能制造构建产业生态圈大数据时代的逐渐逼近&#xff0c;使得传统行业面临巨大的挑战。区块链技术是大数据时代备受关注的新星&#xff0c;在越来越多的领域进行试点应用&#xff0c;区块链技术也是大数据时代日益强盛的关…

Array 复制到ArrayList中

string[] array new string[]{" 1", "2"," 3", "4"," 5" }; ArrayList list new ArrayList();一&#xff1a;使用for循环&#xff0c;将array数组中的数据逐步加入到ArrayList的对象中&#xff1b; //1、for循环 …

OpenCV学习笔记(1)——显示图片

最近开始学习OpenCV了&#xff0c;也打算通过写博客来记录学习opencv的笔记吧。 第一个程序就是比较简单&#xff0c;也是入门级的程序--加载图片并显示出来。 代码如下&#xff1a; #include"highgui.h"int main() {//从文件中提取图像IplImage * imgcvLoadImage(&q…

和包支付的钱哪里来_2019年支付宝年度账单出炉,来看看你究竟花了多少钱

今天早上&#xff0c;打开支付宝付款时&#xff0c;看见搜索框出现2019年账单时&#xff0c;该来的还是要要来。随后&#xff0c;小盾打开支付宝年度帐单看了起来&#xff0c;顿时就心中就出现了这样的疑问&#xff0c;我哪来的这么多钱&#xff1f;我怎么花了这么多钱&#xf…

从RGB到Lab色彩空间的转换

最近一直在学习绘制RGB,HSV,Lab色彩空间的直方图&#xff0c;其中也涉及到互相转换的知识&#xff0c;这是网上看到的介绍的。 虽然若干年前就看过了关于色彩空间的介绍&#xff0c;但是直到今天才自己动手写代码做这件事情。虽然网络上已经有很多现成的例子&#xff0c;但是一…

强制将IE8设置为IE7兼容模式来解析网页(转)

英文原文&#xff1a;http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx 文件兼容性用于定义让IE如何编译你的网页。此文件解释文件兼容性&#xff0c;如何指定你网站的文件兼容性模式以及如何判断一个网页该使用的文件模式。 前言 为了帮助确保你的网页在所有未来…

css中怎么把数字改成罗马数字,$\LaTeX$笔记:Section 编号方式(数字、字母、罗马)计数器计数形式修改...

$\LaTeX$系列根目录&#xff1a; Latex学习笔记-序IEEE模板中Section的编号是罗马数字&#xff0c;要是改投其他刊物的话可能得用阿拉伯数字&#xff0c;所以可以在导言部分做如下修改(放在导言区宏包调用之后)&#xff1a;\renewcommand\thesection{\arabic{section}}%arabic …

creo动画如何拖动主体_Animate如何制作动态遮罩文字动画

使用遮罩可以制作文字动画&#xff0c;让文字变形图片填充并变化的动画效果。FLASH如何制作变色文字效果-百度经验​jingyan.baidu.comFLASH如何制作高光扫过文字的效果-百度经验​jingyan.baidu.com适用软件&#xff1a;Animate CC2018及其它FLash软件制作步骤&#xff1a;1.打…

CvArr、Mat、CvMat、IplImage、BYTE转换(总结而来)

转载自http://blog.csdn.net/wuxiaoyao12/article/details/7305848 一、Mat类型&#xff1a;矩阵类型&#xff0c;Matrix。 在openCV中&#xff0c;Mat是一个多维的密集数据数组。可以用来处理向量和矩阵、图像、直方图等等常见的多维数据。 Mat有3个重要的方法&#xff1a; 1…

Android权限【大全】 .

1 android.permission.ACCESS_CHECKIN_PROPERTIES 2 //允许读写访问”properties”表在checkin数据库中&#xff0c;改值可以修改上传 3 4 android.permission.ACCESS_COARSE_LOCATION 5 //允许一个程序访问CellID或WiFi热点来获取粗略的位置 6 7 android.permission.ACCESS_FI…

css高度背景怎么填充整屏,004-CSS怎样让背景充满整个屏幕

...Your content goes here...给body标签指定背景图&#xff0c;这样背景图就可以填充整个浏览器viewport了。其实&#xff0c;该方案对所有的块级容器都可以生效。块级容器的宽高是动态的&#xff0c;那么背景图将自动伸缩&#xff0c;充满整个容器。CSS body标签的样式如下&a…

pcap python 生成_python+pcap+dpkt 抓包小实例

1 #!/usr/bin/env python2 #-*- coding: utf-8 -*-34 """网络数据包捕获与分析程序"""56 importpcap7 importdpkt8 importjson9 importre10 importtime11 from urllib importunquote1213 #过滤输出目标ip14 dst_lists [15 203.66.1.212, #nslook…

计算机视觉、机器学习相关领域论文和源代码大集合

原文转自&#xff1a;http://blog.csdn.net/zouxy09/article/details/8550952 计算机视觉、机器学习相关领域论文和源代码大集合--持续更新…… zouxy09qq.com http://blog.csdn.net/zouxy09 注&#xff1a;下面有project网站的大部分都有paper和相应的code。Code一般是C/C或者…

热插拔服务器电源维修,无需关停系统即可热插拔,TE Connectivity推出滑轨电源连接器...

原标题&#xff1a;无需关停系统即可热插拔&#xff0c;TE Connectivity推出滑轨电源连接器全球连接与传感器领域领军企业TE Connectivity(TE)宣布推出滑轨电源连接器。此连接器是唯一一款无需关闭系统电源&#xff0c;即可在服务器中进行电子元件热插拔的电源连接器产品。滑轨…