1

假设我想用laravel5(一个 PHP 框架)写一个网页,直接从 Kindle 的网页浏览器下载一个 mobi/awz3 文件。代码如下所示(请参阅上面给出的链接了解详细信息):

return response()->download(storage_path().'/kindle/'.urldecode($filename).$ext, $fileoutput);

第一个参数是fullpath文件的。第二个参数是filename

我面临以下问题:

虽然我可以通过正确的文件名设置从我的计算机下载它,但当我从Kindle 的默认浏览器 Silk$fileoutput下载时,文件名总是丢失。我检查了响应标头,即:

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

我猜丝绸浏览器只读取第一个filename=".azw3"而无法从后者获取文件名filename*=utf8...

有什么想法可以解决这个问题吗?

更新

经过第二次搜索,我发现只有当文件名是 时才会出现问题chinese,即$fileoutput纯英文时,然后filenameheader中的第一个是正确的。

4

0 回答 0