问题描述
- php 下载中文图片报错问题
-
放在不同页面中运行他会报出下载的图片不存在的错误但是我的图片存在
英文的图片名可以但是中文的图片名就报文件不存在为什么?帮忙改正一下。。。。
ShowPicture.php页面如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">无标题文档
点击下载
点击下载
<?php
$str = urlencode("顺平.jpg");
echo "点击下载"
?>
点击下载DownPicture.php页面如下:
<?php
header("Expires: -1");
header("Cache-Control: no_cache");
header("Pragma: no-cache");
header("Content-Type: text/html; charset=utf-8");
require 'class/fileDown.class.php';
$name=urldecode($_REQUEST["name"]);
//echo $name;
down_file($name,"/MianXiangDuixiang/down/");
?>
fileDown.class.php页面如下:
<?php
header("Expires: -1");
header("Cache-Control: no_cache");
header("Pragma: no-cache");
header("Content-Type: text/html; charset=utf-8");
function down_file($file_name,$file_sub_dir)
{
$file_name=iconv("gb2312","GBK",$file_name);
$file_path = $_SERVER['DOCUMENT_ROOT'].$file_sub_dir.$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-Ranges: bytes");
header("Accept-Length: $file_size");
header("Content-Disposition: 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);
}
?>