search
Homephp教程PHP源码下载文件--针对大多数的文件类型

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

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);
}

                   

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!