我做了一個腳本,根據請求服務器將返回一個特定的文件從外部源下載,我使用外部源,因爲我有其他服務器上的無限帶寬:PHP - 從外部服務器下載文件,文件名有引號「'」:'filename.zip'
$ch = curl_init();
$url="http://www.example.com/downloads/$fileName";
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true); // make it a HEAD request
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$head = curl_exec($ch);
$mimeType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
$size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: $mimeType");
header("Content-length: $size");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition:attachment;filename='$fileName'");
readfile($url);
$ filename來自前端的請求。這是一個簡單的帖子。
一切都很正常,但是一些用戶來說,不是所有的,都報告說,他們無法打開該文件,因爲文件名有引號:'filename.zip'
,而不是filename.zip
我碰了壁,我不知道即使開始尋找,顯然這發生在一些mac用戶。有任何想法嗎?
那麼,那是因爲你在倒數第二行加上引號。 ':我' – Sammitch
我認爲這些都是需要的。 – multimediaxp
我們都是對的,[你需要雙引號](https://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1)。看到邁克的回答。 – Sammitch