blueimp/jQuery-File-Upload — Issue #965: Setting Access-Control-Allow-Origin header on target server upload handler, but getting "Origin is not allowed" error.
Author: ariestav
Created: 2012-01-22 03:44:35+00:00
State: open

I'm trying to implement the jQuery-File-Upload module into a PHP webpage that is hosted on 'localhost'. I want the file uploader to store files on a remote server (www.mytargetdomain.com).

Here is how I wrote the

tag for the page that will show the actual uploader's UI:

So, I am pointing the uploader's UI to the correct script on the server. The code in "process_uploads.php" is taken directly from the Sub-folder example code on GitHub. Only, to make it cross-domain capable, I add this line of code directly before the instantiation of the UploadHandler object:

header('Access-Control-Allow-Origin: http://localhost');
$upload_handler = new UploadHandler();

When I go to visit the uploader UI (http://localhost/fileuploader.php) with Chrome, and add a file, then start, Chrome's console gives me this error:

XMLHttpRequest cannot load http://www.mytargetdomain.com/scripts/process_uploads.php. Origin http://localhost is not allowed by Access-Control-Allow-Origin.

Is there another place where I should be placing the header() code so that requests coming from 'http://localhost' are allowed?