[英]Remote Upload (using blueimp file upload plugin)
遠程上傳:通過給定的 URL 上傳文件。
我想使用blueimp
插件將遠程上傳添加到我的網站。 我找到了這個鏈接: https://gist.github.com/blueimp/5075976 ,但我使用外部服務器上傳我的文件,所以當我寫這段代碼時,我收到錯誤:
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.
帶有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);
}
});
我該如何解決?
非常感謝! 對不起我的英語
在remote-file-copy.php
<?php
之后添加這一行
header("Access-Control-Allow-Origin: *");
這將告訴瀏覽器允許來自其他來源的 javascript 訪問您的 php 文件中的內容,如果您只想從您的站點允許您也可以這樣做:
header("Access-Control-Allow-Origin: http://yourmaindomain.com");
更多閱讀: MDN , enable-cors.org , 另一個問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.