使用查询字符串时下载属性损坏的文件名
我有一个按以下方式调用的文件:/storage/1_aviary-image-1429352137570.jpeg?1646327099
。在刀片视图中,我创建了一个下载链接:
<a href="{{ $item['url'] }}" class="btn btn-sm btn-default"
download="{{ $item['url'] }}" target="_blank">
<span class="fa fa-download"></span>
</a>
当我下载文件时,由于某种原因,我得到: _storage_1_aviary-image-1429352137570.jpeg_1646327099
如您所见 ?
已替换为 _
。
我从来没有遇到过这个问题,有人可以帮助我了解发生了什么事吗?
亲切的问候
I have a file called in the following way: /storage/1_aviary-image-1429352137570.jpeg?1646327099
. Within the blade view I have created a download link:
<a href="{{ $item['url'] }}" class="btn btn-sm btn-default"
download="{{ $item['url'] }}" target="_blank">
<span class="fa fa-download"></span>
</a>
When I download the file, for some reason I get: _storage_1_aviary-image-1429352137570.jpeg_1646327099
As you can see the ?
was replaced by _
.
I have never encountered this problem, could someone help me to understand what's going on?
Kind regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于,
download
的属性 value 是可选的,设置后将设置下载文件的名称。如果您未设置它,则文件名将是您在href
值中指定的文件名。也就是说,在不设置
download
值的情况下,以下内容是有效的:由于
?
不是有效的文件名字符,因此它会被下划线优雅地替换。解决方案是不包含
download
值的?
,而是将其保留在href
值中。解决方案:
其中
$item['filename']
是要下载的文件的名称,不带?
和时间戳。The problem is that the attribute value for
download
is optional, and when set will set what downloaded file will be named as. If you don't set it, then the filename will be what you for it in thehref
value.That is, the following is valid, without setting
download
's value:Since a
?
is not a valid filename char, it is being gracefully replaced by the underscore.The solution then is to not include the
?
for thedownload
's value, but keep it in yourhref
value.SOLUTION:
Where
$item['filename']
would be the name of the file to download without the?
and timestamp.