The header function is widely used in php. The header can not only send the original HTTP header information to the client, but also directly implement the file download operation. Next, the editor will introduce it to you and welcome all friends for reference.
The header function is most commonly used not for downloading but for sending http classes
Jump
It will execute the last one, but conditionally, for example:
The code is as follows | Copy code | ||||||||
header('Location:http://www.g.cn'); header('Location:http://www.baidu.com');
header('Location:http://www.bKjia.c0m');echo 'Bang Ke Home; header('Location:http://www.g.cn');
|
代码如下 | 复制代码 |
header('HTTP/1.1 404 Not Found'); |
Output the status value to the browser, mainly used for access control
The code is as follows | Copy code | ||||
|
代码如下 | 复制代码 |
header(‘Content-type: application/octet-stream’);//输出的类型,根据下面提供的MIME表,选择相应的类型 header(‘Content-Disposition: attachment; filename=”下载显示名字.rar”‘);//下载显示的名字 readfile(‘服务器上的文件名.rar’);// |
The code is as follows | Copy code |
header('HTTP/1.1 404 Not Found'); <🎜> header("status: 404 Not Found"); <🎜> ?> |
The code is as follows | Copy code |
$filename = 'path + actual file name'; <🎜> //Type of file <🎜> header('Content-type: application/pdf'); <🎜> //Download the displayed name <🎜> header('Content-Disposition: attachment; filename="File name when saving.pdf"'); <🎜> readfile("$filename"); <🎜> exit(); <🎜> ?> |
The code is as follows | Copy code |
header('Content-type: application/octet -stream');//Output type, select the corresponding type according to the MIME table provided below header(‘Content-Disposition: attachment; filename=”Download display name.rar”‘);//Download display name readfile(‘File name on the server.rar’);// |
要下的文件,包括路径
常用的MIME类型
.doc application/msword
.docx application/vnd.openxmlformats-officedocument.wordprocessingml.document
.rtf application/rtf
.xls application/vnd.ms-excel application/x-excel
.xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.ppt application/vnd.ms-powerpoint
.pptx application/vnd.openxmlformats-officedocument.presentationml.presentation
.pps application/vnd.ms-powerpoint
.ppsx application/vnd.openxmlformats-officedocument.presentationml.slideshow
.pdf application/pdf
.swf application/x-shockwave-flash
.dll application/x-msdownload
.exe application/octet-stream
.msi application/octet-stream
.chm application/octet-stream
.cab application/octet-stream
.ocx application/octet-stream
.rar application/octet-stream
.tar application/x-tar
.tgz application/x-compressed
.zip application/x-zip-compressed
.z application/x-compress
.wav audio/wav
.wma audio/x-ms-wma
.wmv video/x-ms-wmv
.mp3 .mp2 .mpe .mpeg .mpg audio/mpeg
.rm application/vnd.rn-realmedia
.mid .midi .rmi audio/mid
.bmp image/bmp
.gif image/gif
.png image/png
.tif .tiff image/tiff
.jpe .jpeg .jpg image/jpeg
.txt text/plain
.xml text/xml
.html text/html
.css text/css
.js text/javascript