我有我的ftp/php跨域請求的問題。通過我的瀏覽器,我可以通過傳遞如下參數來訪問內容:http://xxx.org/models/get.php?file=default_app/y_car_new/stock.jpg。但用JavaScript相同的鏈接給了我地http://localhost:8000 is not allowed by Access-Control-Allow-Origin
我已經嘗試過PHP來源是不允許的訪問控制允許來源
標題(「訪問控制允許來源:*」)
與下面的腳本沒有運氣。我有一個get.php文件在我的ftp訪問只有服務器與以下代碼:
<?
if(isset($_GET["file"])) {
$filepath = "/.../models/".$_GET["file"];
//echo "path: " , $filepath;
$filetype = pathinfo($filepath);
//echo $filetype['extension'], "\n";
header('Access-Control-Allow-Origin: *');
header('Content-Type: '.$filetype['extension']);
// //header('Content-Type: application/octet-stream');
header('Content-Length: ' . filesize($filepath));
ob_clean();
readfile($filepath);
}//if
else {
echo '<img src="http://stupidbadmemes.files.wordpress.com/2013/02/no-you-may-not.jpg"></img>';
}
?>
我在這個腳本中做錯了什麼?
發送跨來源頭與響應一起是有點兒毫無意義的。這就像授予訪問銀行保險庫的權限,方法是將其寫入存儲在保管庫中的備註上。無法進入保險庫,因爲您沒有說明您可以進入的註釋,並且因爲鎖定在裏面而無法獲取註釋。 – 2013-04-10 16:34:02