最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Failed to load resource: the server responded with a status of 405 (Method Not Allowed) - Stack Overflow

programmeradmin5浏览0评论

good morning.

I have done a ton of research for the past few days and still cannot seem to resolve the following error:

"Failed to load resource: the server responded with a status of 405 (Method Not Allowed) http://localhost:35913/Scripts/upload.php"

the file is in fact at this location because if I go to the URL it downloads the PHP file.

trying to acplish using filedrop.js. Need to drag and drop excel files and get first column of nicknames and have them automatically upload to a gridview.

upload.php:

<?php
/*!
  FileDrop Revamped - server-side upload handler sample
  in public domain  | 

 ***

  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 page:

<asp:Content ID="Content2"  ContentPlaceHolderID="MainContent" runat="server">
<div id="zone3">
  <p class="legend">Drop a file inside...</p>
</div>

       <script src=".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>

good morning.

I have done a ton of research for the past few days and still cannot seem to resolve the following error:

"Failed to load resource: the server responded with a status of 405 (Method Not Allowed) http://localhost:35913/Scripts/upload.php"

the file is in fact at this location because if I go to the URL it downloads the PHP file.

trying to acplish using filedrop.js. Need to drag and drop excel files and get first column of nicknames and have them automatically upload to a gridview.

upload.php:

<?php
/*!
  FileDrop Revamped - server-side upload handler sample
  in public domain  | http://filedropjs

 ***

  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 page:

<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./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>
Share asked Oct 6, 2014 at 18:43 Christopher PetersonChristopher Peterson 931 gold badge3 silver badges12 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

As you had said the file is in fact at this location because if I go to the URL it downloads the PHP file., that means PHP file is not getting executed , rather downloaded as simple file. To make it executable, 1st you have to put that to Apache server and try that URL instead.

problem was sendTo('Scripts/upload.php') had to be changed to sendTo('').

发布评论

评论列表(0)

  1. 暂无评论