PHP はファイルをダウンロードするためのシンプルな汎用メソッドを実装しています

WBOY
リリース: 2016-07-25 08:45:16
オリジナル
730 人が閲覧しました
  1. function download_file($file){
  2. if(is_file($file)){
  3. $length = filesize($file);
  4. $type = mime_content_type($file);
  5. $showname = ltrim(strrchr($ file,'/'),'/');
  6. header("Content-Description: ファイル転送");
  7. header('Content-type: ' . $type);
  8. header('Content-Length:' . $ length);
  9. if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) { //IE の場合
  10. header('Content-Disposition:attachment; filename="' . rawurlencode($showname) . ' "');
  11. } else {
  12. header('Content-Disposition:attachment; filename="' . $showname . '"');
  13. }
  14. readfile($file);
  15. exit;
  16. } else {
  17. exit( '文件已被删除!
PHP

ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!