Heim >Backend-Entwicklung >PHP-Tutorial > php下载文件 图片不能打开,该怎么解决
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 />