Home > Backend Development > PHP Tutorial > 下载png格式的图片,弹出来php文件格式的下载,求解决解决办法

下载png格式的图片,弹出来php文件格式的下载,求解决解决办法

WBOY
Release: 2016-06-13 12:17:11
Original
1319 people have browsed it

下载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));
这样才行

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