Home > Backend Development > PHP Tutorial > 为什么我写的PHP下载代码,下载下来的文件是.php文件?

为什么我写的PHP下载代码,下载下来的文件是.php文件?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:07:33
Original
990 people have browsed it

PHP下载文件代码,下载的确是.php的文件。是怎么回事?在网上查了一下好像说是php.ini的配置问题,求教怎么配置。
代码如下:
$file_name='dx.jpg';


$file_name=iconv("utf-8","gb2312",$file_name);
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("Contect-Dispositon: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);


回复讨论(解决方案)

header("Content-Disposition: attachment; filename=".$file_name);
请对比一下差别

非常感谢版主,问题解决

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