2013-10-18 23 views
0

我通過PHP請求文件從網絡服務器下載,在網絡服務器上以LA6zneL的形式存儲。例如PDF,但用戶必須以其原始文件名獲得它。 因此,我調用這個URLPHP/nginx瀏覽器差異:下載文件「Architecture 8th Edition.pdf」as「Architecture%208th%20Edition.pdf」

LA6zneL.pdf?f=William Stallings Computer Organization and Architecture 8th Edition.pdf 

通過火狐/ Safari瀏覽器/歌劇用戶下載它的文件名

William%20Stallings%20Computer%20Organization%20and%20Architecture%208th%20Edition.pdf 

,但在Chrome/Internet Explorer中它是好的

William Stallings Computer Organization and Architecture 8th Edition.pdf 

我不知道如何通過PHP來完成?在我的腦海中,剛剛出現了用' - '代替所有''字符的解決方案,例如f參數。

這裏是nginx的配置:

add_header Content-Type "application/octet-stream"; 
add_header Content-disposition "attachment; filename=$arg_f"; 

感謝您的時間。

Btw。剛剛在ServerFault上發現了同樣的問題,沒有回覆,希望有人會指出我的位置。 https://serverfault.com/questions/469837/how-to-send-file-names-with-spaces-to-user-with-nginx

回答

0

解決!

PHP:

$arg_f = base64_encode($arg_f); 

Nginx的

add_header Content-Type "application/octet-stream"; 
set_by_lua $filename "return ngx.decode_base64(ngx.var['arg_f'])"; 
add_header Content-disposition "attachment; filename=\"$filename\"";