【发布时间】:2012-11-10 11:53:04
【问题描述】:
下载.php
} else {
$filename = NULL;
}
$err = '<div align="center">GREEK error msg</div>';
if (!$filename) {
// if variable $filename is NULL or false display the message
echo $err;
} else {
// define the path to your download folder plus assign the file name
$path = '../downloads/'.$filename;
// check that file exists and is readable
if (file_exists($path) && is_readable($path)) {
// get the file size and send the http headers
$size = filesize($path);
header('Content-Type: application/octet-stream;');
header('Content-Length: '.$size);
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Transfer-Encoding: binary');
// open the file in binary read-only mode
// display the error messages if the file can´t be opened
$file = @ fopen($path, 'rb');
if ($file) {
// stream the file and exit the script when complete
fpassthru($file);
exit;
} else {
echo $err;
}
} else {
echo $err;
}
}
?>
我就是这样称呼它的:
<a href="scripts/download.php?file=GREEKCHARS_Earth.pdf"></a>
如果文件名是英文,下载脚本可以正常工作。
如果文件名是希腊语,则会显示错误消息。如果我 echo $filename 我看到了正确的希腊名称,所以我认为正确的名称是在我的 download.php 中传递的。
由于我得到 $filename 的正确名称,并且我的实际文件具有相同的名称,脚本在哪里无法下载我的文件并给出错误消息? p>
似乎无法将希腊语 $filename 与实际文件匹配。
【问题讨论】:
-
试试
header('Content-Disposition: attachment; filename='.rawurlencode($filename)); -
这有很多地方会搞砸。首先,服务器接收到的值是否正确?尝试
bin2hex()ing$_GET值并检查这些是否是“ΔΨΞ”(CE94CEA8CE9E)的实际 UTF-8 字节。 -
@deceze
echo bin2hex($_GET) . "<br />";什么也不输出。echo bin2hex($filename) . "<br />";输出:cea42ece942e5f3039385f -
产生
cea42ece942e5f3039385f的字符串是什么? -
好的。 Τ.Δ._003_GammaRAE_II_R 输出 cea42ece942e5f3030335f47616d6d615241455f49495f522e706466