Home > Article > Backend Development > 下载png格式的图片,弹出来php文件格式的下载,求解决解决办法
下载png格式的图片,弹出来php文件格式的下载,求解决
function down_file($file_name,$file_path){
@$file_name=iconv("utf_8","gb2312",$file_name);
$file_path=$_SERVER['DOCUMENT_ROOT'].$file_path.$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-Rangers: bytes");
header("Accept-Length: $file_size");
header("Content-Dispostion: attachment;filename=".$file_name);
while(!feof($file_path)){
$data=fread($fp,1024);
echo $data;
}
fclose($fp);
}
down_file("php.png","/down/");
?>
------解决思路----------------------
加个下载类型试试 header("content-type: image/png");
------解决思路----------------------
header("Content-Dispostion: attachment;filename=".$file_name);
这个是带路径的了吧
header("Content-Dispostion: attachment;filename=".basename($file_name));
这样才行