练习php文件上载,上载的图片打不开

WBOY
Release: 2016-06-13 10:33:05
Original
941 people have browsed it

练习php文件下载,下载的图片打不开
$file_name="hello.jpg";
if(!file_exists($file_name))
{
echo "文件不存在";
return;
}
$fp=fopen($file_name,"r");
//获取下载文件大小
$file_size=filesize($file_name);
echo $file_size;
//返回的文件
header("Content-type: application/octet-stream");
//按照字节大小返回
header("Accept-Ranges: byte");
//返回文件大小
header("Accept-Length: $file_size");
//这里客户端的弹出对话框,对应的文件名
header("Content-Disposition: attachment;filename=".$file_name);


$buffer=1024;
//判断文件是否到结尾,结束
while(!feof($fp))
{
//echo "1111";
$file_data=fread($fp,$buffer);
//把部分数据回送给浏览器
echo $file_data;
}
fclose($fp);
?>


打不开图片文件的提示是:因为此文件可能已经损坏,或者过大

------解决方案--------------------
echo $file_size; //这句注释掉

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