title: POST 405 Not Allowed with Particular XMLHttpRequest and PHP
body: <p>I am getting a POST <a href="https://www.example.com/php/download.php" rel="nofollow">https://www.example.com/php/download.php</a> 405 (Not Allowed) with this ajax call to my php script. It is for a http file server that I wrote to download files...grab them outside of web root using php. My other PHP scripts/ajax calls work for my http file server...I am only getting this issue with this particular ajax call/php script. I am using Nginx. </p>
  
  <p>Again, just to emphisize....On this same server other ajax calls and other php scripts work. So, kinda lost. </p>
  
  <pre><code>&lt;?php
  
  $path = "/trunk/";
  $file = $_POST['filename'];
  $file_ext = pathinfo($file, PATHINFO_EXTENSION);
  $file_name = pathinfo($file, PATHINFO_BASENAME);
  $file_full = $path . $file_name;
  
  $finfo = new finfo(FILEINFO_MIME);
  
  $ctype = $finfo -&gt; file($file_full);
  header('Content-Disposition: attachment; filename=\"$file_name\"');
  header("Content-Type: " .$ctype);
  
  readfile($file_full);
  
  ?&gt;
  
  187 
  188 function downloadFile(event) {
  189         var fname = event.target.getAttribute("href");
  190         fname.replace("#","");
  191         var form = new FormData();
  192         form.append("filename", fname);
  193         
  194         var xhr = new XMLHttpRequest();
  195         xhr.onreadystatechange = function () {
  196 //              setTimeout(refresh, 500);
  197         }
  198         
  199         xhr.open("POST", "php/download.php", true);
  200         xhr.send(form);
  201 }
  </code></pre>
  
  <p>Here is from Google's chrome network debugger: </p>
  
  <pre><code>Request URL:https://www.example.com/php/download.php
  Request Method:POST
  Status Code:405 Not Allowed
  Request Headersview source
  Accept:*/*
  Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
  Accept-Encoding:gzip,deflate,sdch
  Accept-Language:en-US,en;q=0.8
  Connection:keep-alive
  Content-Length:172
  Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryNGHvOaUnlBV8ADWE
  Host:www.example.com
  Origin:https://www.example.com
  Referer:https://www.example.com/index.php
  User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4
  Request Payload
  ------WebKitFormBoundaryNGHvOaUnlBV8ADWE
  Content-Disposition: form-data; name="filename"
  
  CentOS-6.3-x86_64-minimal-EFI.iso
  ------WebKitFormBoundaryNGHvOaUnlBV8ADWE--
  Response Headersview source
  Connection:keep-alive
  Content-Length:568
  Content-Type:text/html
  Date:Fri, 30 Nov 2012 23:59:59 GMT
  Keep-Alive:timeout=300
  Server:nginx
  </code></pre>