阅读背景:

PHP 文件下载程序 文件打包下载

来源:互联网 

相信这个程序大家都还是有需要的。就是做文件下载呀之类的可以使用。先看下程序

function downloadFile($file, $name){
    if (@$fp = fopen($file,'r')){  
         header ("Content-type: octet/stream"); 
         $name = '[模宝]'.$name; 
         if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE")){ 
            if(stristr($file, '.txt')){
              header("Content-Disposition: attachment; filename=".mb_convert_encoding($name,'GB2312','UTF-8')); // For txt   
            }else{
              header("Content-Disposition: filename=".mb_convert_encoding($name,'GB2312','UTF-8')); // For IE    
            }  
         }else{  
            header("Content-Disposition: attachment; filename=".mb_convert_encoding($name,'GB2312','UTF-8')); // For Other browsers   
         } while(!@feof($fp)){  
             echo fread($fp,1024);   
         }   
         exit();   
    } else{  
     print "此文件不存在";  
    }  
}func



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: