2011-08-03 103 views
2

我在我的网站上使用Valums Ajax Uploader。一切工作正常我本地计算机上,但是当我尝试我的网站主服务器上的相同上传然后Firbug显示了这个错误:valums Ajax文件上传+ 406不可接受Error in 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> 

所有请求&响应头是herefileuploader.js的文件代码到附近号线1204:

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

upload.php也在正确的文件夹,我通过直接访问它来检查它 – Peeyush

+0

是否一个简单的'.txt'文件上传没有错误?还是所有的上传都失败了? – andyb

+0

no .txt也会导致相同的406错误 – Peeyush

回答

0

我觉得mod_security的凑了过来。这似乎是一个(只?)来解决,这是通过添加到您.htaccess禁用后置扫描方式如下:

<ifmodule mod_security.c> 
SecFilterScanPOST Off 
</ifmodule> 

我想尝试的.htaccess添加到您的应用程序的根目录下,并希望它的工作原理因为托管服务提供商可能不允许用户特定的.htaccess文件。

相关文章 - http://tech.shantanugoel.com/2008/05/01/http-406-errors-galore.html

+0

我在.htaccess文件中添加了这个,但仍然给出了406错误 – Peeyush

+0

您可能无法[覆盖](http://httpd.apache.org/docs/2.2/mod /core.html#allowoverride)托管服务提供商设置。你问过他这件事吗? http://corz.org/serv/tricks/htaccess.php也是'.htaccess'的有用摘要 – andyb

0

我不知道这是否会帮助您解决问题,但我最近使用JQuery $就碰到这个同样的问题来了POST'ing。我也有类似的问题使用JQuery Qaptcha,它也使用了一些Ajax和POST。

在这两次我都能够将POST更改为GET(包括正在调用的php文件中),然后它将在我的主机的活动服务器上运行。

我还没有完全理解这样做的好坏,因为我在这个领域相当缺乏经验,所以如果有人有任何想法,这是否是一件坏事,那么输入将不胜感激。

例子:

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或专用服务器上,你可以自己做出所需的更改。

希望有所帮助。

2

问题出在mod_security。

也许,如果内容编码与表单不同(不是multipart/form-data或form-urlencoded),则您有阻止所有文件上载请求的规则。

首先 - 你可以在你的apache配置文件中注释该行。

第二个(对于valums uploader更方便) - 为你的fileuploader添加encoding:'multipart'选项 - 这将为Content-Encoding添加multipart/form-data,这样apache将允许这个请求。

+0

如何将multipart/form-data添加到ajax请求中? – albanx

+0

对于值的上传者添加参数 编码:'multipart', –

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可以预见一些安全漏洞的服务器端。