下载文件--针对大多数的文件类型

PHP中文网
リリース: 2016-05-25 16:58:53
オリジナル
1120 人が閲覧しました

下载文件--针对大多数的文件类型

function forceDownLoad($filename='' ,$data=''){
     if($filename==''  OR  $data==''){  return false; }
     if(FLASE === strpos($filename,'.')){
        return false;
     }
     $x = explod('.',$filename);
     $extension = end($x);
     $mimes = array('hqx'=>'application/mac-binhex40','cpt'=>'application/mac-compactpro','csv'=>'text/x-comma-separated-values','text/csv','application/csv','application/excel','application/vnd.msexcel','bin'=>'application/macbinary','dms'=>'application/octet-stream','lha'=>'application/octet-stream','lzh'=>'application/octect-stream','exe'=>array('application/octet-stream'));

if(!isset($mimes[$extension])){  $mime = 'application/octet-stream'; }
else{ $mime = (is_array($mimes[$extension]); ))?$mimes[$extension][0]: $mimes[$extension]; }

header('Content-type:"'. $mime.'"');
$tmpName = $filename;
$filename = '"''.urlencode($tmpName)."'; ////IE 中文名支持
if(strstr(strtolower($_SERVER['HTTP_USER_AGER']),'firefox') !=false){   $filename='" .$tmpName."';}  /////Firefox 中文支持
if(strstr(strtolower($_SERVER['HTTP_USER_AGER']),'chrome') !=false){   $filename='" .$tmpName."';}  /////Chrome 中文支持

header('Content-Disposition:attachment; filename='. $filename);
header('Expires:0');
header('Cache-Control: must-revalidate,post-check=0,pre-check=0');
header('Content-Transfer-Encoding:binary');
header('Pragma:no-cache');
header('Content-Length:'.strlen($data));

exit($data);
}
ログイン後にコピー

                   

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