应用程序/强制下载

发布于 2024-08-07 13:31:32 字数 426 浏览 7 评论 0原文

我正在创建一个仅上传 zip 文件的脚本,并且已准备好以下验证:

if($itemtype != "application/x-zip-compressed"
   && $itemtype != "application/zip" && $itemtype != "application/octet-stream") {
  throw new exception("Your file should be a zip file!");
}

但我有一个文件类型为 application/force-download 的文件,但当我查看 mime 类型时,我可以'找不到它,我是否还应该将其添加到验证中(参见上面的代码)?我尝试上传的文件应该是一个普通的 zip 文件......好吧,这就是我的想法

I'm creating a script to only upload zip files and I have the following validation allready:

if($itemtype != "application/x-zip-compressed"
   && $itemtype != "application/zip" && $itemtype != "application/octet-stream") {
  throw new exception("Your file should be a zip file!");
}

but I have a file with file type application/force-download but when I look in the mime types I can't find it, should I still add it in the validation (see code above)? the file I try to upload should be a normal zip file ... well that's what I thought

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千と千尋 2024-08-14 13:31:32

修复示例中的代码并使您的问题更加清晰。

也就是说,尚不清楚您是要尝试验证上传的文件还是下载的文件。

我将大胆猜测并说您可能正在尝试提供已上传的文件。 Mimetypes 是一种非常糟糕的验证方式,但您的问题实际上可能出在您的网络主机上。在过去的类似情况下,我看到共享托管提供商在未经我许可的情况下插入各种标头,导致类似于您可能遇到的问题(如果您的问题更精确的话)。不幸的是,这种特殊情况下的解决方案是用 php 重写整个下载服务流程,这本身就有很多问题。

Fix your code in your example and make your question more clear.

That said, it's unclear whether you're trying to validate an uploaded file or a downloaded file.

I'm going to take a wild guess and say that you might be trying to serve a file that's already uploaded. Mimetypes are a pretty bad way of validating that, but your problem might actually lie with your webhost. In similar situations in the past, I've seen shared hosting providers inserting all kinds of headers without my permission, resulting in problems similar to what you might be experiencing, were your question more precise. Unfortunately, the solution in that particular case was to re-write the entire serving process for the download in php, which had a whole bunch of problems of its own.

丢了幸福的猪 2024-08-14 13:31:32

您需要检查文件扩展名,而不是内容类型。特别是,因为不同的浏览器可以发送不同的内容类型。

You need to check file extension, not the content type. Especially, because different browsers can send different content types.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文