title: PHP header not working for Access-Control-Allow-Origin
body: <p>I am using the <a href="http://blueimp.github.io/jQuery-File-Upload/">jQuery File Upload plugin by Blueimp</a> to upload images to a server.  The problem is, the sending server is <code>admin.example.com</code>, and the receiving server where the images are stored is on <code>www.example.com</code>.  Same domain, different subdomain.</p>
  
  <p>I followed the <a href="https://github.com/blueimp/jQuery-File-Upload/wiki/Cross-domain-uploads#cross-site-xmlhttprequest-file-uploads">instructions here on setting up cross-domain uploads</a>, and everything seems to be correct as far as code, but when I try to upload the images, I get this error:</p>
  
  <pre><code>XMLHttpRequest cannot load http://www.example.com/upload/. Origin http://admin.example.com is not allowed by Access-Control-Allow-Origin.
  </code></pre>
  
  <p>The upload folder does have read and write permissions.</p>
  
  <p>I'm going to post my code below-if anyone can show me how to fix this, please let me know.  I had asked about this before and was going to try some other solutions (iframe uploads and ftp file moving).  Neither of these will be best for my situation, and it would be easiest if I could just do it this way...</p>
  
  <p><strong>RECEIVING SERVER</strong></p>
  
  <pre><code>index.php
  
  &lt;?php
      header('Access-Control-Allow-Origin: http://admin.example.com');  //I have also tried the * wildcard and get the same response
      header("Access-Control-Allow-Credentials: true");
      header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
      header('Access-Control-Max-Age: 1000');
      header('Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description');
  ?&gt;
  &lt;?php
  
      error_reporting(E_ALL | E_STRICT);
      require('UploadHandler.php');
      $upload_handler = new UploadHandler();
  </code></pre>
  
  <p><strong>SENDING SERVER</strong></p>
  
  <pre><code>main.js
  
  $(function () {
      'use strict';
  
      // Initialize the jQuery File Upload widget:
      $('#fileupload').fileupload({
          // Uncomment the following to send cross-domain cookies:
          xhrFields: {withCredentials: true},
          url: 'http://admin.example.com/upload/',
          disableImageResize: false,
          dropZone: $('#dropzone'),
          imageMaxWidth: 1800,
          imageMaxHeight: 1800,
      });
  });
  </code></pre>
  
  <p>Again I've tried the iframe file upload, so please don't suggest it unless you can give me full working code...</p>
  
  <p>I have also tried <code>header('Access-Control-Allow-Origin: *');</code> but get the same error...I'm trying to get this finished by the weekend so I'd appreciate any help I can get. :)</p>
  
  <p>Thanks!</p>
  
  <p>EDIT: here's the response headers for the failed OPTIONS request</p>
  
  <pre><code>Allow:OPTIONS, TRACE, GET, HEAD, POST
  Content-Length:0
  Date:Tue, 27 Aug 2013 15:08:29 GMT
  Public:OPTIONS, TRACE, GET, HEAD, POST
  Server:Microsoft-IIS/7.5
  X-Powered-By:ASP.NET
  </code></pre>