Home > Backend Development > PHP Tutorial > php下载文件 图片不能打开

php下载文件 图片不能打开

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 14:06:16
Original
1277 people have browsed it

 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);
Copy after login

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


回复讨论(解决方案)

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

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

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