Question

Remote upload: Upload files via a given URL.

I want to add a remote upload to my website using blueimp plugin. I found this link:https://gist.github.com/blueimp/5075976, but I use an external server to upload my files, so when I write this code, I get the error:

Uncaught SecurityError: Blocked a frame with origin "http://myExternalURL.com" from accessing a frame with origin "http://www.myMainWebsite.com". Protocols, domains, and ports must match. 

The part of the code with the url:

$('#remote-file-copy').on('submit', function (e) {
    e.preventDefault();
    var url = $(this).find('input').val(),
        iframe = $('<iframe src="javascript:false;" style="display:none;"></iframe>');
    if (url) {
        iframe
            .prop('src', 'http://I-USE-EXTERNAL-URL/remote-file-copy.php?url=' + encodeURIComponent(url))
            .appendTo(document.body);
    }
});

How can I fix it?

Thank you very much! and sorry for my English

Was it helpful?

Solution

add this line right after <?php in remote-file-copy.php

header("Access-Control-Allow-Origin: *");

this will tell the browser to allow javascript from other origins to access content from your php file , if you only want to allow from your site you can also do this:

header("Access-Control-Allow-Origin: http://yourmaindomain.com");

more reading on this: MDN ,enable-cors.org, another question

see also : chrome-blocks-different-origin-requests

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top