本文实例为大家分享了php header函数下载文件实现代码,供大家参考,具体内容如下
http://www.php.net/manual/en/function.readfile.php
<".//images//" . $file; //First, see if the file exists if (! is_file ( $file )) { die ( "<b>404 File not found!</b>" ); } // Gather relevent info about file $len = filesize ( $file ); $filename = basename ( $file ); $file_extension = strtolower ( substr ( strrchr ( $filename, "." ), 1 ) ); // This will set the Content-Type to the appropriate setting for the file switch ($file_extension) { case "pdf" : $ctype = "application/pdf"; break; case "exe" : $ctype = "application/octet-stream"; break; case "zip" : $ctype = "application/zip"; break; case "doc" : $ctype = "application/msword"; break; case "xls" : $ctype = "application/vnd.ms-excel"; break; case "ppt" : $ctype = "application/vnd.ms-powerpoint"; break; case "gif" : $ctype = "image/gif"; break; case "png" : $ctype = "image/png"; break; case "jpeg" : case "jpg" : $ctype = "image/jpg"; break; case "mp3" : $ctype = "audio/mpeg"; break; case "wav" : $ctype = "audio/x-wav"; break; case "mpeg" : case "mpg" : case "mpe" : $ctype = "video/mpeg"; break; case "mov" : $ctype = "video/quicktime"; break; case "avi" : $ctype = "video/x-msvideo"; break; // The following are for extensions that shouldn't be downloaded // (sensitive stuff, like php files) case "php" : case "htm" : case "html" : case "txt" : die ( "<b>Cannot be used for " . $file_extension . " files!</b>" ); break; default : $ctype = "application/force-download"; } $file_temp = fopen ( $file, "r" ); // Begin writing headers header ( "Pragma: public" ); header ( "Expires: 0" ); header ( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ); header ( "Cache-Control: public" ); header ( "Content-Description: File Transfer" ); // Use the switch-generated Content-Type header ( "Content-Type: $ctype" ); // Force the download $header = "Content-Disposition: attachment; filename=" . $filename . ";"; header ( $header ); header ( "Content-Transfer-Encoding: binary" ); header ( "Content-Length: " . $len ); //@readfile ( $file ); echo fread ( $file_temp, filesize ( $file ) ); fclose ( $file_temp ); exit (); } ?>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年11月18日
2024年11月18日
- 林子祥《单手拍掌》华纳香港版[WAV+CUE][1G]
- 郑秀文.1997-我们的主题曲【华纳】【WAV+CUE】
- 群星.2001-生命因爱动听电影原创音乐AVCD【MEDIA】【WAV+CUE】
- 林志颖.1994-别了晴雨的回忆【飞碟】【WAV+CUE】
- 群星《经典咏流传2》限量1:1母盘直刻[低速原抓WAV+CUE]
- 【蓝卡唱片】卫海霞《乐海霞音珍藏版》WAV分轨
- 杨小琳《金装杨小琳》24K金碟特别版[低速原抓WAV+CUE]
- 群星《国风超有戏 第8期》[320K/MP3][30.32MB]
- 群星《国风超有戏 第8期》[FLAC/分轨][157.37MB]
- 群星《说唱梦工厂 第10期》[320K/MP3][99.5MB]
- 李嘉.1996-思念过秋冬【点将】【WAV+CUE】
- 汪峰.2009-信仰在空中飘扬【星文】【WAV+CUE】
- 尤长靖.2023-肆无忌惮的恋人(EP)【FLAC分轨】
- 群星《说唱梦工厂 第10期》[FLAC/分轨][544.11MB]
- 群星《歌手2024 第12期》[320K/MP3][105.71MB]