假设我想用 laravel5 (一个PHP框架)编写一个网页,直接从kindle的webbowser下载一个mobi / awz3文件。代码看起来像(请参阅上面给出的链接了解详细信息):
return response()->download(storage_path().'/kindle/'.urldecode($filename).$ext, $fileoutput);
第一个参数是文件的fullpath
,第二个参数是filename
。
我遇到以下问题:
虽然我可以通过$fileoutput
使用正确的文件名设置从我的计算机下载,但当我从 kindle的默认bowser silk 下载时,文件名总是丢失。我检查了响应头,即:
Accept-Ranges: bytes
Cache-Control: public
Connection: keep-alive
Content-Disposition: attachment; filename=".azw3"; filename*=utf-8''%E6%B5%AE%E7%94%9F%E5%85%AD%E8%AE%B0.azw3
Content-Length: 1526943
Content-Type: application/octet-stream
Date: Fri, 26 Aug 2016 14:22:06 GMT
Last-Modified: Sat, 28 May 2016 05:55:45 GMT
Server: nginx/1.6.2
Set-Cookie: XSRF-TOKEN=eyJpdiI6IjNBSmV6Q0R6QU8wWTlhSHU2TlFtYmc9PSIsInZhbHVlIjoiYnBGSThcL1wvaFRCSXNUUnIwZjVyR2M3anhMOUFBUDhTeU9zRGI4ODJzbEVCZ3FQMnF6XC81MFBITXJFY0xQQ0s2MytLdGQ5ZGVsUTNPMGdDb09xbXdmNXc9PSIsIm1hYyI6ImUyNTU1YjdjOTMxNDE1NTk1MDg1ZTFiODVhYTYxNTIzZTc0MDg3MzQyNjg0YzQ0MjlkYjllYjYyNTNhNDMwMmUifQ%3D%3D; expires=Fri, 26-Aug-2016 16:22:06 GMT; Max-Age=7200; path=/
laravel_session=eyJpdiI6IlVNY1h4MmVSOGZaS3A2bHRSZkJMWGc9PSIsInZhbHVlIjoiRWtBK01jeHBPZnhEdlVQckh1VkhwTmlNYTBQSHlLUWd6aEY1dmpaMUIzVzNGa1Q2cnZIY1FUcUl3REtLTUdwSTE2OHRXZldDSEVPT2VIZVUzV2JUVkE9PSIsIm1hYyI6IjE5OGQ5MDVhZGMzYzJjZWRjMmNjY2FlYTQxNjc0ZTU4YjkyZTFmYzk2Yjg3YmIwZGNkYWQxMjA0M2UwZTIwYTMifQ%3D%3D; expires=Fri, 26-Aug-2016 16:22:06 GMT; Max-Age=7200; path=/; httponly
strict-transport-security: max-age=15768000
与之相比(从amazon.com下载电子书):
Accept-Ranges: bytes
Content-Disposition: attachment; filename=-.azw3; filename*=UTF-8''%e4%b8%89%e5%9b%bd%e6%bc%94%e4%b9%89%20%28%e5%8f%a4%e5%85%b8%e5%90%8d%e8%91%97%e6%99%ae%e5%8f%8a%e6%96%87%e5%ba%93%29.azw3
Content-Length: 1086746
Content-Type: application/x-mobi8-ebook
Date: Fri, 26 Aug 2016 14:55:50 GMT
Etag: "atv:kin:2:7em8xElPVsRobIXa1NiUa2s2zfXgvBRZ8wJeuKk3OeNpRWnSDSkae0GhbcBTm6GbPZdDY/1CbRICldAJKv4gtiK8SMCbGLLWYrJkKurs0VVe3SB6fEgXLtuEirb2OPJMbvVftnTgCXLEEeGe128ba53v7vM/ABoIgQrWCBD7zXs=:vuRb/GOXZICuuca026R6sJpOCdE=:7l7eh3kzFhCeES7yH/6BYA=="
Hint-Sidecar-Download: 0
ResumableDownloadToken: atv:kin:2:7em8xElPVsRobIXa1NiUa2s2zfXgvBRZ8wJeuKk3OeNpRWnSDSkae0GhbcBTm6GbPZdDY/1CbRICldAJKv4gtiK8SMCbGLLWYrJkKurs0VVe3SB6fEgXLtuEirb2OPJMbvVftnTgCXLEEeGe128ba53v7vM/ABoIgQrWCBD7zXs=:vuRb/GOXZICuuca026R6sJpOCdE=:7l7eh3kzFhCeES7yH/6BYA==
Server: Amazon Web Server
x-adp-host: H2KOCVSR4J4L1J
我想 silk bowser 只会读取第一个filename=".azw3"
而无法从后一个filename*=utf8...
获取文件名。
有什么想法解决这个问题吗?
更新
经过第二次搜索后,我发现问题只发生在文件名是chinese
时,也就是说,当$fileoutput
是纯英语时,标题中的第一个filename
是正确的。