当前位置:Gxlcms > PHP教程 > php下载文件图片不能打开

php下载文件图片不能打开

时间:2021-07-01 10:21:17 帮助过:11人阅读

 function fileDown($file_name){        $file_name = iconv("utf-8","gb2312",$file_name);        $file_path = "E:/php/down/".$file_name;        if(!file_exists($file_path)){            echo "文件不存在";            return;        }        $fp = fopen($file_path,"r");        $file_size = filesize($file_path);        Header("Content-type: application/octet-stream");        Header("Accept-Ranges: bytes");        Header("Accept-Length: $file_size");        Header("Content-Disposition: attachment; filename=".$file_name);        $buffer = 1024;        $file_count = 0;        while(!feof($fp) && ($file_size - $file_count>0)){            $file_data = fread($fp,$buffer);            $file_count += $buffer;            echo $file_data;        }        fclose($fp);    }	$file_name="sai.png";	fileDown($file_name);

文件能够下载,但是图片打不开。以前能够打开。别的机器访问这个文件也能打开


回复讨论(解决方案)

首先检查是否有 BOM 头
不过 别的机器访问这个文件也能打开 ,那么可能性不大

去除了bom头确实可以了。为什么以前没有问题,在别的机器上访问也没问题

人气教程排行