应用程序/强制下载 [英] application/force-download

查看:153
本文介绍了应用程序/强制下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个仅上传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!");
}

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

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

推荐答案

在示例中修复代码,使问题更清楚.

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.

我要大胆地猜测,您可能正在尝试提供已经上传的文件. Mimetypes是验证这一点的非常糟糕的方法,但是您的问题实际上可能出在您的Web主机上.在过去的类似情况下,我曾看到共享托管服务提供商未经我的许可而插入各种标头,如果您的问题更精确,则会导致与您可能遇到的问题类似的问题.不幸的是,在这种情况下,解决方案是用php重新编写下载的整个服务过程,这本身就有很多问题.

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.

这篇关于应用程序/强制下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆