文章也很简单我们只要用利用head发送头部信息就能实现把文件下载到本地了,有直接发送header信息也有把文件保存在服务器上再用header来发送哦,有需要的朋友参考下。
用的是表头方式下载,代码如下:
- 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);
判断文件存在再下载代码如下:
- <?php
- if( isset( $_REQUEST["download"] ) )
- {
- $tfile = $_REQUEST["download"];
- if (file_exists($tfile))
- {
- $downfilename=substr($tfile,strrpos($tfile, "/")+1);
- //文件保存的名字可以修改为你需要的,可以和链接给的名字不一样
- // 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文件下载,代码如下:
- <?php
- $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"); //pdf格式的
- ?>
下面讲讲header中的Content-type,不同的下载文件,对应不同的content-type,下面是大全:
- {
- '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',
- }
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
波比源码 » php 文件下载方法
波比源码 » php 文件下载方法
buy levaquin 250mg levofloxacin 250mg usa
cialis 10mg pills canadian online pharmacy cost viagra
buy deltasone 40mg generic cialis us sildenafil 100mg tablet
order prograf for sale labetalol brand buy ursodiol sale
zyprexa order order nebivolol sale diovan 160mg tablet
prilosec usa order omeprazole generic casino world
purchase clomid sale order ventolin online best play money poker sites
slot games free free online roulette gambling addiction
tamsulosin 0.4mg pill buy tamsulosin sale aldactone 25mg pill
tadalafil women cialis 20mg pills viagra pills 150mg
viagra price levitra or viagra cialis from india
trazodone 50mg generic trazodone cheap aurogra 100mg usa
sildenafil next day delivery buy estradiol pill order lamotrigine 50mg for sale
generic prednisone 20mg prednisone 40mg usa amoxil 1000mg ca
azithromycin price zithromax 250mg generic neurontin online buy
lasix buy online hydroxychloroquine price plaquenil 200mg cost
cost fildena budesonide spray rhinocort for sale online
buy tiotropium bromide without prescription tiotropium bromide for sale terazosin 1mg over the counter
cost singulair 10mg viagra 25mg price sildenafil 50mg us
order tadalafil 40mg sale buy cialis 10mg online cheap cialis online
casino real money online slots san manuel casino online
free spins no deposit usa slots free online casino real money no deposit
order nifedipine pills buy nifedipine 30mg without prescription fexofenadine 180mg over the counter
doxycycline cost buy doxycycline cost cleocin
buy generic temovate amiodarone drug buy amiodarone 100mg sale
Thank you for great article. Hello Administ . Metropol Halı Karaca Halı Öztekin ve Selçuklu Halı Cami Halısı ve Cami Halıları Türkiye’nin En Büyük Cami Halısı Fabrikasıyız…
esomeprazole medication buy lasix 40mg buy furosemide 100mg sale
purchase minocycline sale gabapentin 100mg cost buy terazosin 5mg for sale
modafinil 100mg generic stromectol 3mg canada order phenergan generic
ivermectin 3mg otc erection pills viagra online oral prednisone 5mg
order prednisolone 40mg for sale prednisolone 5mg tablet buy furosemide 40mg without prescription