使用“IFRAME”上传影像PHP创建HTTP代理 [英] Create a http proxy in php for uploading images using 'iframe'

查看:106
本文介绍了使用“IFRAME”上传影像PHP创建HTTP代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用案例:我的工作,它使用 AJAX上传<图像上传/ A> function.I要上传图片到一个子域的website.For例如用户创建,当用户创建我复制一个PHP脚本,上传图像到新域即网​​站上的域名图像cropping.php 。我想,当用户上传任何图片给他的域发送请求到该文件。

Use Case: I am working on an image uploader which uses ajax upload function.I want to upload images to a subdomain user creates on the website.For example,when the user creates a domain on the website I copy a php script for uploading images to the new domain viz image-cropping.php.I want to send a request to this file when the user uploads any image to his domain.

问题
当我尝试上载我得到一个像错误:权限被拒绝访问财产的readyState 。我调用 js文件 xyz.google.com 和上传PHP脚本是 abc.google.com

Issue:
When I try to upload an image I get Error: Permission denied to access property 'readyState'.My calling js file is on xyz.google.com and the upload php script is on abc.google.com.

研究
做一些google搜索和研究之后,我学会了JavaScript的将不允许发送请求跨域,它需要一个HTTP代理服务器来处理this.Here是code我tried.The脚本运行阿贾克斯uploader.In动作我有路径上的其他域文件(路径是动态生成的)。

Research
After doing some googling and research I learnt javascript won't allow to send request cross domain and it needs a http proxy to handle this.Here is the code I have tried.The script to run the ajax uploader.In action I have the path to file on other domain(the path is built dynamically).

   new AjaxUpload(btnUpload, {
        action: 'includes/modules/domain_creation/proxy.php',
        name: 'image',
        onSubmit: function(file, ext){
            if (! (ext && /^(jpg|png|jpeg|gif|JPG|JPEG|PNG|GIF)$/.test(ext))){ 
                alert('Only JPG, PNG or GIF files are allowed');
                return false;
            }
            $('#thumbImg').html('<img src="http://localhost/gobiggi_VS_2_2/images/appImages/imageLoader.png" />');
        },

1)我在正确的方式(工作于它的第一次)做什么呢?是在代理实际需要
2)如何以及在哪里可以设置代理这样的错误权限可以协商?
3)它打开了哪些安全问题(它是安全的吗?如果不是出了什么替代)?任何指针或建议将是对我有帮助。
感谢您的时间。

1) Am I doing it in the right way(working on it for first time)?Is the proxy actually needed?
2)How and where can I set the proxy so that the error permission can be negotiated?
3)What security issues does it open up(Is it safe?If not what's an alternative)?Any pointers or suggestions would be helpful for me.
Thank you for your time.

更新:
我使用该代理
脚本中上传的code的image.Part是

Update:
I am using this proxy script for uploading the image.Part of the code is

   $domainUsername = $_SESSION['domainUsername'];
   $domainNameWeb = $_SESSION['domainName'];
   //$fileParameterProxy = $_FILES['image'];
   //Destination URL: Where this proxy leads to the upload script
     $destinationURL = 'http://www.'.$domainNameWeb.'/'.$domainUsername.'/upload.php';
   //The only domain from which requests are authorized.
   $RequestDomain = 'abc.net';

现在我没有得到错误许可,但我没能获得在图像上的server.When我尝试做的print_r($ _ FILES)我得到我的上传脚本空数组。

Now I don't get the Error for permission but I am not able to get the image on to the server.When I try to do print_r($_FILES) I get a blank array on my upload script.

我相信,我失去了一些东西!有人可以纠正?
感谢您的时间!

I believe I am missing something!!Can someone please correct?
Thank you for your time!

推荐答案

1和2)必须设置为操作您的代理,因为那是你被允许上传的文件的地方。然后,代理将执行请求发送到其他领域,在那里可以将文件发送到

1 and 2) You have to set your proxy as action, because that is the place where you are allowed to upload the files. The proxy then will do the request to the other domain, where it can send the files to.

3)取决于你的代理实现。你应该避免在本地存储文件或执行/包括从用户输入任何东西,写PHP脚本时等。直接发送tmp文件到目标服务器,这也将是最快的实现。

3) Depends on your proxy implementation. You should avoid to store the files locally or execute/include anything from user input, like always when writing php scripts. Directly send the tmp file to your destination server, this will also be the fastest implementation.

这篇关于使用“IFRAME”上传影像PHP创建HTTP代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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