PHP头不能用于Access-Control-Allow-Origin [英] PHP header not working for Access-Control-Allow-Origin

查看:618
本文介绍了PHP头不能用于Access-Control-Allow-Origin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Blueimp的 jQuery文件上传插件将图片上传到服务器。问题是,发送服务器是 admin.example.com ,图像存储的接收服务器在 www.example.com 。相同的网域,不同的子网域。

I am using the jQuery File Upload plugin by Blueimp to upload images to a server. The problem is, the sending server is admin.example.com, and the receiving server where the images are stored is on www.example.com. Same domain, different subdomain.

我按照设置跨域上传的说明,一切似乎是正确的代码,但当我尝试上传图像,我得到此错误:

I followed the instructions here on setting up cross-domain uploads, and everything seems to be correct as far as code, but when I try to upload the images, I get this error:

XMLHttpRequest cannot load http://www.example.com/upload/. Origin http://admin.example.com is not allowed by Access-Control-Allow-Origin.

上传文件夹具有读写权限。

The upload folder does have read and write permissions.

我将在下面发布我的代码 - 如果任何人都可以告诉我如何解决这个问题,请让我知道。我曾经问过这个,并将尝试一些其他解决方案(iframe上传和ftp文件移动)。这些都不是最好的我的情况,这将是最简单的,如果我可以这样做...

I'm going to post my code below-if anyone can show me how to fix this, please let me know. I had asked about this before and was going to try some other solutions (iframe uploads and ftp file moving). Neither of these will be best for my situation, and it would be easiest if I could just do it this way...

接收服务器

index.php

<?php
    header('Access-Control-Allow-Origin: http://admin.example.com');  //I have also tried the * wildcard and get the same response
    header("Access-Control-Allow-Credentials: true");
    header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
    header('Access-Control-Max-Age: 1000');
    header('Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description');
?>
<?php

    error_reporting(E_ALL | E_STRICT);
    require('UploadHandler.php');
    $upload_handler = new UploadHandler();

SENDING SERVER

main.js

$(function () {
    'use strict';

    // Initialize the jQuery File Upload widget:
    $('#fileupload').fileupload({
        // Uncomment the following to send cross-domain cookies:
        xhrFields: {withCredentials: true},
        url: 'http://admin.example.com/upload/',
        disableImageResize: false,
        dropZone: $('#dropzone'),
        imageMaxWidth: 1800,
        imageMaxHeight: 1800,
    });
});

再次,我尝试了iframe文件上传,所以请不要建议,除非你能我完全工作代码...

Again I've tried the iframe file upload, so please don't suggest it unless you can give me full working code...

我也试过了 header('Access-Control-Allow-Origin:*'); 但得到相同的错误...我试图让这个周末完成,所以我会感谢任何帮助,我可以得到。 :)

I have also tried header('Access-Control-Allow-Origin: *'); but get the same error...I'm trying to get this finished by the weekend so I'd appreciate any help I can get. :)

感谢!

EDIT:以下是失败的OPTIONS请求的响应标头

here's the response headers for the failed OPTIONS request

Allow:OPTIONS, TRACE, GET, HEAD, POST
Content-Length:0
Date:Tue, 27 Aug 2013 15:08:29 GMT
Public:OPTIONS, TRACE, GET, HEAD, POST
Server:Microsoft-IIS/7.5
X-Powered-By:ASP.NET


推荐答案

没有得到任何解决方案,所以我把它移到一个临时目录并使用FTP将其移动到另一个域....

Didn't get any solutions, so I just moved it to a temporary directory and used FTP to move it to another domain....

这篇关于PHP头不能用于Access-Control-Allow-Origin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆