【发布时间】:2013-04-11 00:34:33
【问题描述】:
我的 ftp/php 跨域请求有问题。使用我的浏览器,我可以通过传递如下参数来访问内容:http://xxx.org/models/get.php?file=default_app/y_car_new/stock.jpg。但是对于 JavaScript,相同的链接给了我 Origin http://localhost:8000 is not allowed by Access-Control-Allow-Origin
我已经试过了
header("Access-Control-Allow-Origin: *")
在下面的脚本中没有运气。我的 ftp 访问服务器中有一个 get.php 文件,代码如下:
<?
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>';
}
?>
我在这个脚本中做错了什么?
【问题讨论】:
-
随响应一起发送跨域标头是毫无意义的。这就像通过将其写在存储在保险库中的票据上来授予访问银行保险库的权限。无法进入保险库,因为您没有可以进入的纸条,并且您无法拿到纸条,因为它被锁在里面。
标签: php ftp cross-domain