我在我的网站上使用Valums Ajax Uploader。在我的本地计算机上一切正常,但是当我在我的网站主服务器上尝试相同的上传程序时,Firbug会显示此错误:
POST http://www.myexampledomain.com/upload.php?qqfile=201004151821387.1.flv 406不可接受8.37s
fileuploader.js(第1204行)
回复正文
<title>406 Not Acceptable</title>
<p>An appropriate representation of the requested resource /upload.php could not be found on this server.</p>
<p>Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.</p>
所有请求&amp;响应标头为here,并且在第1204行附近的fileuploader.js
文件代码中为:
params = params || {};
params['qqfile'] = name;
var queryString = qq.obj2url(params, this._options.action);
xhr.open("POST", queryString, true);
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.setRequestHeader("X-File-Name", encodeURIComponent(name));
xhr.setRequestHeader("Content-Type", "application/octet-stream");
xhr.send(file); //line 1204
我已经在谷歌和这个网站上搜索过,但没有找到任何有用的信息,请告诉我如何解决这个问题?
关于此问题的其他问题 - 406 error on firebug only
答案 0 :(得分:2)
问题在于mod_security。
如果内容编码与表单不同(不是multipart / form-data或form-urlencoded),您可能会阻止所有文件上传请求。
首先 - 您可以在apache配置文件中注释该行。
第二个(对于valums uploader更方便) - 添加编码:'multipart'选项到你的文件上传器 - 这将为Content-Encoding添加multipart / form-data,这样apache就会允许这个请求。
答案 1 :(得分:1)
我遇到了同样的问题,我通过禁用.htaccess文件中的mod_security解决了这个问题
<IfModule mod_security.c>
# Turn off mod_security filtering.
SecFilterEngine Off
# The below probably isn't needed,
# but better safe than sorry.
SecFilterScanPOST Off
</IfModule>
请使用以上风险,因为禁用mod_security可以预见某些安全漏洞服务器端。
答案 2 :(得分:0)
我认为mod_security
正在阻碍。似乎只有一种(仅?)解决方法是通过向.htaccess
添加以下内容来禁用POST扫描:
<ifmodule mod_security.c>
SecFilterScanPOST Off
</ifmodule>
我会尝试将.htaccess
添加到您的应用程序的根目录,并希望它可以正常工作,因为托管服务提供商可能不允许用户特定的.htaccess
文件。
相关文章 - http://tech.shantanugoel.com/2008/05/01/http-406-errors-galore.html
答案 3 :(得分:0)
我不确定这是否有助于解决您的问题,但我最近遇到了使用JQuery $ .ajax进行POST的相同问题。我在使用JQuery Qaptcha时遇到了类似的问题,它也使用了一些ajax和一个POST。
在这两种情况下,我都可以将POST更改为GET(包括正在调用的php文件中),然后它将在我的主机的实时服务器上运行。
我还没有完全明白这样做的好坏,因为我在这个领域缺乏经验,所以如果有人想知道这是否是一件坏事,那么输入将会受到赞赏。< / p>
示例:
if($cust_acceptance == 'yes') {
$.ajax({
type: "GET", //Swapped out a POST for a GET.
url: "/scripts/php/update_shortlist.php",
data: "action=add&shortlist_id="+shortlist_id+"&rb_ref="+rb_ref,
success: function(msg){
//alert ("success: "+rb_ref);
我认为其他人是正确的,因为mod_security存在权限问题,但如果您使用的是共享服务,则不太可能说服您的托管公司为您更改这些设置。显然,如果您使用的是VPS或专用服务器,您可以自己进行更改。
希望有所帮助。