下载文本文件都没有问题,但是下载语音文件和应用程序会出现问题,比如语音文件无法播放,应用程序无法运行。
例如我上传了一个notepad.exe的应用程序,点击下载之后无法运行。editplus打开发现上面多了3行空行,应该是
我写的下载文件有问题,贴出来请大家指教。if(file_exists($get_File) && !strstr($get_File,"..") && strlen(trim($get_File))>0 && strlen(trim($get_File))>strlen(trim($curdir)))
{
        //获得参数
$filename = basename(trim($get_File));
$get_Size = filesize($get_File) ; //获取文件类型
$finfo = finfo_open(FILEINFO_MIME, '/usr/share/misc/magic');
$get_MimeType = finfo_file($finfo, $get_File); //下载头文件定义
header("Cache-Control: no-store, no-cache, must-revalidate\n"); 
header("Content-Description: File Transfer\n"); 
header("Content-disposition: attachment; filename=".$filename."\n"); 
header("Content-Type: $get_MimeType\n"); 
header("Content-Transfer-Encoding: binary\n"); 
header("Content-Length: ".$get_Size."\n\n");         //打开附件缓冲
if($FD = fopen($get_File,"r"))
{
//下载文件流
fpassthru($FD); //关闭打开附件
fclose($FD);
exit(0);
}
}其中$get_File是文件的绝对路径,下载是以type=clean的方式~

解决方案 »

  1.   

    1.PHP上可能有空行
    2.直接用readfile读取文件看看
      

  2.   

    检查了,php文件上面没有空格。还会是什么问题呢?
      

  3.   

    if($FD = fopen($get_File,"r"))
    换成
    if($FD = fopen($get_File,"rb"))如果还不行的话:
    1)存在3个文件
    A:上传以前的可执行文件
    B:上传以后保存在服务器上的可执行文件
    C:下载以后的可执行文件A是没有问题的,那么你看看B和C究竟是哪个被破坏了.(比较文件大小,用Binary Editor比较内容)
    如果是B,那么你的上传程序有问题.
    如果是C,那么下载过程有问题.
      

  4.   

    if($FD = fopen($get_File,"r"))
        {
            //下载文件流
            fpassthru($FD);        //关闭打开附件
            fclose($FD);
            exit(0);
        }
    这个地方定义的好像就是文本文件的下载...像 .exe 可以直接 src 连接 下载