- Header ("Content-Type: application/vnd. ms-excel ")
-
If you want to provide the open/save dialog box, the Content-Disposition parameter and the Content-Disposition parameter are intended to provide a recommended file name when the client saves another file, however, this parameter is removed from the specification for security reasons. Content-Disposition parameter: attachment --- download inline as attachment --- open online Specific use:
- Header ("Content-Disposition: inline; filename ");
- Header ("Content-Disposition: attachment?filename=test.xls ");
-
In fact, IE identifies the file type based on the filename suffix in the Content-Disposition segment. if there are many file types, you can set Content-Type to binary: Header ("Content-type: application/octet-stream "); Example:
- $ Filename = './download/d.rar ';
- $ Filesize = filesize ($ filename );
- Header ("Content-Type: application/force-download ");
- Header ("Content-Disposition: attachment; filename =". basename ($ filename ));
- Header ("Content-Length:". $ filesize );
- $ Data = file_get_contents ($ filename );
- Echo $ data;
- ?>
-
The download and save window appears immediately after the preceding code is opened. the downloaded file is $ filename. Some common mimetype types: $ Mimetypes = array ('Doc' => 'application/msword', 'bin' => 'application/octet-stream ', 'exe '=> 'application/octet-stream', 'so' => 'application/octet-stream', 'dll' => 'application/octet-stream ', 'PDF '=> 'application/pdf', 'Ai' => 'application/postscript ', 'XLS' => 'application/vnd. ms-excel ', 'ppt' => 'application/vnd. ms-powerpoint ', 'dir' => 'application/x-ctor', 'js' => 'application/x-javascript ', 'swf '=> 'application/x-shockwave-Flash', 'xhtml' => 'application/xhtml + XML ', 'xht '=> 'application/xhtml + XML', 'Zip' => 'application/zip', 'mid '=> 'audio/midi ', 'midi '=> 'audio/midi', 'mp3' => 'audio/mpeg ', 'rm' => 'audio/x-pn-realaudio ', 'rpm '=> 'audio/x-pn-realaudio-plugin', 'wav' => 'audio/x-wav ', 'bmp '=> 'image/bmp', 'GIF' => 'image/GIF', 'jpeg '=> 'image/jpeg ', 'jpg '=> 'image/jpeg', 'PNG '=> 'image/png', 'css '=> 'text/css ', 'HTML '=> 'text/html', 'htm' => 'text/html', 'txt' => 'text/plain ', 'xsl '=> 'text/XML', 'xml' => 'text/XML', 'MPEG' => 'video/mpeg ', 'mpg' => 'video/mpeg ', 'Av' => 'video/x-msvideo ', 'movie '=> 'video/x-sgi-movie ',);>>> Articles you may be interested in: when downloading the php header function file, you are prompted to save the useful php header download function. php get_headers checks whether the URL is valid. PHP header function Usage example: php header function usage example (2) php header function usage example (1) php header usage example php header information application example php sending various types of file downloads example PHP header message explanation |