- Header ("Content-type:application/vnd.ms-excel")
Copy CodeIf you want to be able to provide that open/Save dialog box, the Content-disposition parameter, the content-disposition parameter is intended to provide a suggested file name when the client saves the file, but for security reasons, This parameter is removed from the specification. Content-disposition parameter: Attachment---as an accessory download inline---open online Specific use:
- Header ("Content-disposition:inline; filename= file name. mp3 ");
- Header ("Content-disposition:attachment;filename=test.xls");
Copy CodeIn fact, IE is based on content-disposition filename in this section of the suffix to identify the file type, if there are many types of file, you can set the Content-type to binary mode: 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;
- ?>
Copy CodeThe above code implementation opens the page immediately after the download saves the window, the download file is $filename. Some common mimetype types: $mimetypes = Array (' Doc ' = ' application/msword ', ' bin ' = ' application/octet-stream ', ' exe ' = ' application/oc ') Tet-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-director ', ' 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 ', ' avi ' = ' Video/x-msvideo ', ' movie ' = ' Video/x-sgi-movie ',);>>> you may be interested in the article: PHP header function File download directly prompt to save good php header download function php get_headers detection URL is valid method PHP header function Usage example PHP Example of the use of the header function (2) PHP header function Usage example (1) PHP header using a detailed PHP header information application example PHP use header send various types of file Download example PHP header message in detail |