gpt4 book ai didi

php - 强制下载瑞典字符 (åäö) 文件名

转载 作者:可可西里 更新时间:2023-10-31 23:48:04 27 4
gpt4 key购买 nike

<分区>

我使用以下代码和函数强制下载文件,如果文件名不包含瑞典语字符(如 Å Ä Ö),它会很好用。

$file_id = $_GET['f'];

$sql = " SELECT * ".
" FROM attachment ".
" WHERE attachment_id = ".$file_id." ".

$res = mysql_query($sql);
$row = mysql_fetch_array($res);
$filename = $row['filename'];
$USER_ID = $row['user_id'];
$Directory_id = $row['directory_id'];
$target_path = "upload/".$USER_ID."/".$Directory_id."/";


function Download($path, $speed = null)
{
if (is_file($path) === true)
{
$file = @fopen($path, 'rb');
$speed = (isset($speed) === true) ? round($speed * 1024) : 524288;

if (is_resource($file) === true)
{
set_time_limit(0);
ignore_user_abort(false);

while (ob_get_level() > 0)
{
ob_end_clean();
}

header('Expires: 0');
header('Pragma: public');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: application/octet-stream');
header('Content-Length: ' . sprintf('%u', filesize($path)));
header('Content-Disposition: attachment; filename="' . basename($path) . '"');
header('Content-Transfer-Encoding: binary');

while (feof($file) !== true)
{
echo fread($file, $speed);

while (ob_get_level() > 0)
{
ob_end_flush();
}

flush();
sleep(1);
}

fclose($file);
}

exit();
}

return false;

}
Download($target_path.$filename);

我试着把它放在我页面的顶部:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

和:

$filename = urlencode($filename); 

或者:

$filename =  htmlentities($filename, ENT_QUOTES, "UTF-8");

还是一样的问题,打不开。但如果文件名包含正常的英文字符,则它可以正常工作。

您有什么建议可以放入或实现该功能吗?非常感谢您提供的任何帮助。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com