Home > Backend Development > PHP Tutorial > 编写下载图片的有关问题

编写下载图片的有关问题

WBOY
Release: 2016-06-13 11:23:16
Original
726 people have browsed it

编写下载图片的问题。

本帖最后由 bianyu1983 于 2013-02-09 22:17:02 编辑 $file_name="420.jpg";
if(!file_exists($file_name)){
echo '文件不存在';
}

$fp=fopen($file_name,"r");

$file_size=filesize($file_name);

header("content-type:appliation/octet-stream");
header("accept-ranges:bytes");
header("accept-length:".$file_size);
header("content-disposition:attachment;filename=".$file_name);
$buffer=1024;
while(!feof($fp)){
$file_data=fread($fp,$buffer);
echo $file_data;

fclose($fp);
上面的代码可以把图片下载下来,下载来的图片不原图片大20个字节。下载下的图片一片空白。

------解决方案--------------------
$fp=fopen($file_name,"rb");
------解决方案--------------------
$file_name="420.jpg";
if(!file_exists($file_name)){
echo '文件不存在';
}
echo后面应该加一个exit;
或者就:
exit("文件不存在。");
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