The article is also very simple, we just use head to send header information can be implemented to download the file to this, there is a direct send header information also has to save the file on the server and then use the header to send Oh, there is a need for friends reference.
Using the table header method to download
The code is as follows |
Copy Code |
Header ("Content-type:application/octet-stream"); Header ("Accept-ranges:bytes"); Header ("Accept-length:". FileSize ($file _dir. $file _name)); Header ("content-disposition:attachment; Filename= ". $file _name); |
Determine the existence of the file and download
code as follows |
copy code |
if (isset ($_request["Download")) { $tfile = $_request["Download"];
if (file_exists ($tfile)) { $downfilename =substr ($tfile, Strrpos ($tfile, "/") +1); File saved name can be changed to you need, can and link to the name is not the same Prompt the user to download the new torrent file. Header ("Content-type:application/octet-streamn"); Header ("content-disposition:attachment; Filename= $downfilenamen "); Header ("Content-transfer-encoding:binaryn"); Header ("Content-length:".) @filesize ($tfile). "N"); Send the torrent file $fp = @fopen ($tfile, "R"); @fpassthru ($FP); @fclose ($FP); }
Exit (); } ?> |
PDF file Download
The code is as follows |
Copy Code |
$filename = $_server[' Document_root '). "/path/to/file/my_file.pdf"; Header ("Cache-control:public"); Header ("Content-description:file Transfer"); Header (' content-disposition:attachment; Filename= '. basename ($filename)); Header ("Content-type:application/pdf"); in PDF format ?> |
Let's talk about the Content-type in the header:
Different download files, corresponding to different content-type, the following is Daquan:
PHP Code
{
' EZ ' = ' application/andrew-inset ',
' hqx ' = ' application/mac-binhex40 ',
' CPT ' = ' Application/mac-compactpro ',
' Doc ' = ' Application/msword ',
' Bin ' = ' application/octet-stream ',
' DMS ' = ' application/octet-stream ',
' Lha ' = ' application/octet-stream ',
' Lzh ' = ' application/octet-stream ',
' exe ' = ' application/octet-stream ',
' Class ' = ' Application/octet-stream ',
' So ' = ' application/octet-stream ',
' dll ' = ' Application/octet-stream ',
' Oda ' = ' Application/oda ',
' PDF ' = ' application/pdf ',
' ai ' = ' application/postscript ',
' EPS ' = ' application/postscript ',
' ps ' = ' application/postscript ',
' SMI ' = ' application/smil ',
' Smil ' = ' application/smil ',
' MIF ' = ' application/vnd.mif ',
' xls ' = ' application/vnd.ms-excel ',
' ppt ' = ' application/vnd.ms-powerpoint ',
' Wbxml ' = ' application/vnd.wap.wbxml ',
' WMLC ' = ' APPLICATION/VND.WAP.WMLC ',
' WMLSC ' = ' APPLICATION/VND.WAP.WMLSCRIPTC ',
' Bcpio ' = ' Application/x-bcpio ',
' VCD ' = ' application/x-cdlink ',
' PGN ' = ' application/x-chess-pgn ',
' Cpio ' = ' Application/x-cpio ',
' csh ' = ' application/x-csh ',
' DCR ' = ' application/x-director ',
' dir ' = ' application/x-director ',
' DXR ' = ' application/x-director ',
' DVI ' = ' application/x-dvi ',
' SPL ' = ' application/x-futuresplash ',
' Gtar ' = ' Application/x-gtar ',
' HDF ' = ' APPLICATION/X-HDF ',
' js ' = ' application/x-javascript ',
' SKP ' = ' Application/x-koan ',
' SKD ' = ' Application/x-koan ',
' Skt ' = ' Application/x-koan ',
' SKM ' = ' Application/x-koan ',
' Latex ' = ' Application/x-latex ',
' NC ' = ' application/x-netcdf ',
' CDF ' = ' application/x-netcdf ',
' sh ' = ' application/x-sh ',
' Shar ' = ' Application/x-shar ',
' swf ' = ' application/x-shockwave-flash ',
' Sit ' = ' application/x-stuffit ',
' Sv4cpio ' = ' Application/x-sv4cpio ',
' SV4CRC ' = ' APPLICATION/X-SV4CRC ',
' Tar ' = ' application/x-tar ',
' Tcl ' = ' application/x-tcl ',
' Tex ' = ' Application/x-tex ',
' Texinfo ' = ' application/x-texinfo ',
' Texi ' = ' application/x-texinfo ',
' t ' = ' application/x-troff ',
' TR ' = ' application/x-troff ',
' Roff ' = ' application/x-troff ',
' Man ' = ' Application/x-troff-man ',
' Me ' = ' application/x-troff-me ',
' ms ' = ' application/x-troff-ms ',
' Ustar ' = ' Application/x-ustar ',
' src ' = ' application/x-wais-source ',
' xhtml ' = ' application/xhtml+xml ',
' Xht ' = ' application/xhtml+xml ',
' Zip ' = ' application/zip ',
' Au ' = ' audio/basic ',
' snd ' = ' audio/basic ',
' Mid ' = ' Audio/midi ',
' midi ' = ' Audio/midi ',
' Kar ' = ' audio/midi ',
' MPGA ' = ' audio/mpeg ',
' MP2 ' = ' audio/mpeg ',
' mp3 ' = ' audio/mpeg ',
' AIF ' = ' audio/x-aiff ',
' Aiff ' = ' Audio/x-aiff ',
' aifc ' = ' Audio/x-aiff ',
' m3u ' = ' audio/x-mpegurl ',
' Ram ' = ' Audio/x-pn-realaudio ',
' rm ' = ' Audio/x-pn-realaudio ',
' rpm ' = ' audio/x-pn-realaudio-plugin ',
' ra ' = ' audio/x-realaudio ',
' wav ' = ' audio/x-wav ',
' pdb ' = ' chemical/x-pdb ',
' xyz ' = ' chemical/x-xyz ',
' BMP ' = ' image/bmp ',
' gif ' = ' image/gif ',
' Ief ' = ' image/ief ',
' jpeg ' = ' image/jpeg ',
' jpg ' = ' image/jpeg ',
' JPE ' = ' image/jpeg ',
' png ' = ' image/png ',
' TIFF ' = ' Image/tiff ',
' tif ' = ' image/tiff ',
' DjVu ' = ' Image/vnd.djvu ',
' DJV ' = ' Image/vnd.djvu ',
' Wbmp ' = ' image/vnd.wap.wbmp ',
' ras ' = ' image/x-cmu-raster ',
' PNM ' = ' image/x-portable-anymap ',
' PBM ' = ' image/x-portable-bitmap ',
' PGM ' = ' image/x-portable-graymap ',
' ppm ' = ' image/x-portable-pixmap ',
' RGB ' = ' Image/x-rgb ',
' XBM ' = ' image/x-xbitmap ',
' xpm ' = ' image/x-xpixmap ',
' xwd ' = ' image/x-xwindowdump ',
' IGs ' = ' model/iges ',
' IGEs ' = ' model/iges ',
' MSH ' = ' Model/mesh ',
' Mesh ' = ' model/mesh ',
' Silo ' = ' model/mesh ',
' WRL ' = ' model/vrml ',
' VRML ' = ' model/vrml ',
' CSS ' = ' text/css ',
' html ' = ' text/html ',
' htm ' = ' text/html ',
' ASC ' = ' text/plain ',
' txt ' = ' text/plain ',
' Rtx ' = ' text/richtext ',
' rtf ' = ' text/rtf ',
' SGML ' = ' text/sgml ',
' SGM ' = ' text/sgml ',
' TSV ' = ' text/tab-separated-values ',
' WML ' = ' text/vnd.wap.wml ',
' wmls ' = ' text/vnd.wap.wmlscript ',
' Etx ' = ' text/x-setext ',
' xsl ' = ' text/xml ',
' xml ' = ' text/xml ',
' mpeg ' = ' video/mpeg ',
' mpg ' = ' video/mpeg ',
' MPE ' = ' video/mpeg ',
' qt ' = ' video/quicktime ',
' mov ' = ' video/quicktime ',
' Mxu ' = ' video/vnd.mpegurl ',
' avi ' = ' video/x-msvideo ',
' Movie ' = ' Video/x-sgi-movie ',
' Ice ' = ' x-conference/x-cooltalk ',
}
http://www.bkjia.com/PHPjc/631684.html www.bkjia.com true http://www.bkjia.com/PHPjc/631684.html techarticle The article is also very simple, we just use head to send header information can be implemented to download the file to this, there is a direct send header information also has to save the file on the server and then use the header to send ...