PHP はファイルをダウンロードするためのシンプルな汎用メソッドを実装しています
リリース: 2016-07-25 08:45:16
- function download_file($file){
- if(is_file($file)){
- $length = filesize($file);
- $type = mime_content_type($file);
- $showname = ltrim(strrchr($ file,'/'),'/');
- header("Content-Description: ファイル転送");
- header('Content-type: ' . $type);
- header('Content-Length:' . $ length);
- if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) { //IE の場合
- header('Content-Disposition:attachment; filename="' . rawurlencode($showname) . ' "');
- } else {
- header('Content-Disposition:attachment; filename="' . $showname . '"');
- }
- readfile($file);
- exit;
- } else {
- exit( '文件已被删除!
-
-
PHP
|
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
著者別の最新記事
-
2024-09-20 15:51:33
-
2024-09-20 15:47:32
-
2024-09-20 15:45:32
-
2024-09-20 15:39:32
-
2024-09-20 15:38:32
-
2024-09-20 15:27:32
-
2024-09-20 15:26:32
-
2024-09-20 15:12:32
-
2024-09-20 14:53:01
-
2024-09-20 14:51:01