php菜鸟求解-关于文件下载

WBOY
Release: 2016-06-13 13:41:02
Original
1082 people have browsed it

php初学者求解--关于文件下载
大家好 我是个新手 正在学习中 刚看了传智播客的视频中关于文件下载的部分 ,按照开始韩老师给的代码自己写了一遍,但是为什么图片是在页面中显示 ,而不是从浏览器下载?

请各位朋友帮帮忙 不胜感激



$file_name="mao.jpg";
if(!file_exists($file_name)) {
echo "文件不存在!";
return;
}
$fp=fopen($file_name,"r");
$file_size=filesize($file_name);

header("Content-type: application/octet-stream");
header("Accept-Ranges: bytes");
header("Accept-Length: $file_size");
header("Content-Disponsition: attachment; filename=".$file_name);

$buffer=1024;
while(!feof($fp)){
$file_data=fread($fp,$buffer);
echo $file_data;
}
fclose($fp);
?>

------解决方案--------------------
header("Content-Disponsition: attachment; filename=".$file_name); 这儿多了个n,所以无效

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!