未能加载资源:服务器的响应状态为405(不允许使用方法)
Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
早上好。
在过去的几天里,我做了大量的研究,似乎仍然无法解决以下错误:
"加载资源失败:服务器响应状态为405(不允许方法)http://localhost:35913/Scripts/upload.php
"
文件实际上就在这个位置,因为如果我转到URL,它会下载PHP文件。
尝试使用filedrop.js完成。需要拖放excel文件,获得第一列昵称,并将其自动上传到网格视图。
upload.php:
<?php
/*!
FileDrop Revamped - server-side upload handler sample
in public domain | http://filedropjs.org
***
This is an example of server-side script that handles both AJAX and IFrame uploads.
AJAX upload provides raw file data as POST input while IFrame is a POST request
with $_FILES member set.
Result is either output as HTML with JavaScript code to invoke the callback
(like JSONP) or in plain text if none is given (it's usually absent on AJAX).
*/
// If an error causes output to be generated before headers are sent - catch it.
ob_start();
// Callback name is passed if upload happens via iframe, not AJAX (FileAPI).
$callback = &$_REQUEST['fd-callback'];
// Upload data can be POST'ed as raw form data or uploaded via <iframe> and <form>
// using regular multipart/form-data enctype (which is handled by PHP $_FILES).
if (!empty($_FILES['fd-file']) and is_uploaded_file($_FILES['fd-file']['tmp_name'])) {
// Regular multipart/form-data upload.
$name = $_FILES['fd-file']['name'];
$data = file_get_contents($_FILES['fd-file']['tmp_name']);
} else {
// Raw POST data.
$name = urldecode(@$_SERVER['HTTP_X_FILE_NAME']);
$data = file_get_contents("php://input");
}
// Output message for this demo upload. In your real app this would be something
// meaningful for the calling script (that uses FileDrop.js).
$output = sprintf('%s; received %s bytes, CRC32 = %08X, MD5 = %s', $name,
number_format(strlen($data)), crc32($data), strtoupper(md5($data)));
// In FileDrop sample this demonstrates the passing of custom ?query variables along
// with an AJAX/iframe upload.
$opt = &$_REQUEST['upload_option'];
isset($opt) and $output .= "'nReceived upload_option with value $opt";
if ($callback) {
// Callback function given - the caller loads response into a hidden <iframe> so
// it expects it to be a valid HTML calling this callback function.
header('Content-Type: text/html; charset=utf-8');
// Escape output so it remains valid when inserted into a JS 'string'.
$output = addcslashes($output, "'''"'0..'x1F");
// Finally output the HTML with an embedded JavaScript to call the function giving
// it our message(in your app it doesn't have to be a string) as the first parameter.
echo '<!DOCTYPE html><html><head></head><body><script type="text/javascript">',
"try{window.top.$callback('"$output'")}catch(e){}</script></body></html>";
} else {
// Caller reads data with XMLHttpRequest so we can output it raw. Real apps would
// usually pass and read a JSON object instead of plan text.
header('Content-Type: text/plain; charset=utf-8');
echo $output;
}
aspx页面:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="zone3">
<p class="legend">Drop a file inside...</p>
</div>
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"> </script>
<script type="text/javascript" src="Scripts/filedrop.js"></script>
<script type="text/javascript">
var zone = new FileDrop('zone3')
zone.event('send', function (files) {
files.each(function (file) {
// Listen for errors:
file.event('error', function (e, xhr) {
alert(xhr.status + ', ' + xhr.statusText)
})
file.sendTo('Scripts/upload.php')
})
})
</script>
正如您所说的the file is in fact at this location because if I go to the URL it downloads the PHP file.
,这意味着PHP文件不会被执行,而是作为简单文件下载。要使其可执行,首先您必须将其放入Apache
服务器,然后尝试使用该URL。
问题是sendTo('Scripts/upload.php')必须更改为sendTo('')。
相关文章:
- 不允许使用引导清单'组件'指令
- 在严格模式下不允许使用八进制文本
- Chrome 不允许使用过期时间少于 4 小时的 Cookie
- 为什么我的代码没有'不允许使用特定符号
- http://0.0.0.0:4567访问控制允许来源不允许.使用Backbone&Firebase
- 使用Google Drive和Angularjs时,不允许使用请求标头字段Accept Encoding
- JavaScript 中不允许的方法
- 输入框中不允许使用数字
- 405:不允许使用方法(AJAX 查询到 Flask)
- 简单购物车不允许使用千个逗号分隔符
- JSON 数据解析器不允许使用单引号
- Web 服务器不允许使用开机自检方法
- 为什么在严格模式下不允许使用八进制数字文字(解决方法是什么?)
- 未能加载资源:服务器的响应状态为405(不允许使用方法)
- pre - flight响应中的Access-Control-Allow-Methods不允许使用PUT方法.在AWS
- 不允许使用自托管WCF REST服务JSON POST方法
- 不允许使用JSONP WCF方法
- Angular.js表单POST返回错误405不允许使用方法
- 错误405:不允许使用方法
- 不允许使用OPTIONS方法.Get工作,但不是POST