Home > Backend Development > PHP Tutorial > php下载文件 图片不能打开,该怎么解决

php下载文件 图片不能打开,该怎么解决

WBOY
Release: 2016-06-13 11:21:34
Original
952 people have browsed it

php下载文件 图片不能打开

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

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


------解决方案--------------------
首先检查是否有 BOM 头
不过 别的机器访问这个文件也能打开 ,那么可能性不大
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template