[英]Cross domain upload class
I finished writing a website and am currently deploying it on a hosting service. 我写完了一个网站,目前正在托管服务上部署它。 This website consists out of 2 separate domains hosted on the same server.
该网站由托管在同一服务器上的2个独立域组成。 (www.domain1.com & www.domain2.com)
(www.domain1.com和www.domain2.com)
Situation 情况
When moving these domains to the hosting service, I figured that 1 script is not working as it was on the local server. 将这些域移动到托管服务时,我认为1个脚本不像在本地服务器上那样工作。 This script is a custom upload class in php.
这个脚本是php中的自定义上传类。 This script is located on www.domain1.com but needs to upload the file to www.domain2.com.
此脚本位于www.domain1.com上,但需要将文件上传到www.domain2.com。
My local server is a Xampp server with a simple file structure. 我的本地服务器是具有简单文件结构的Xampp服务器。
C:/xampp/htdocs C:/ XAMPP / htdocs中
Domain1/uploadscript.php 域1 / uploadscript.php
Domain2/destinationfolder/ 域2 / destinationfolder /
I am currently using the $_SERVER['DOCUMENT_ROOT']
function to navigate towards the other domain. 我目前正在使用
$_SERVER['DOCUMENT_ROOT']
函数导航到其他域。 This method works fine for the local server but not on the hosted version see below. 此方法适用于本地服务器,但不适用于托管版本,请参阅下文。
Main issue 主要问题
Local server print_r ($_SERVER['DOCUMENT_ROOT']);
本地服务器
print_r ($_SERVER['DOCUMENT_ROOT']);
= C:/xampp/htdocs
= C:/ xampp / htdocs
On domain1.com print_r ($_SERVER['DOCUMENT_ROOT']);
在domain1.com上打印
print_r ($_SERVER['DOCUMENT_ROOT']);
= /home/myname/domains/domain1/public_html/
= / home / myname / domains / domain1 / public_html /
On domain2.com print_r ($_SERVER['DOCUMENT_ROOT']);
在domain2.com上打印
print_r ($_SERVER['DOCUMENT_ROOT']);
= /home/myname/domains/domain2/public_html/
= / home / myname / domains / domain2 / public_html /
The $_SERVER['DOCUMENT_ROOT']
is not pointing to the "domains" folder but already is pointing to the "public_html" . $_SERVER['DOCUMENT_ROOT']
未指向“domains”文件夹,但已指向“public_html” 。
The question(s) 问题
How do I navigate towards the "domains" folder on my server? 如何导航到服务器上的“domains”文件夹? Are there other things necessary for cross domain uploading?
是否还有其他必要的跨域上传?
If you want to send some cross domain data, you should set Access-Control-Allow-Origin
header. 如果要发送一些跨域数据,则应设置
Access-Control-Allow-Origin
标头。
You can do this in your .htaccess
like below: 您可以在
.htaccess
执行此操作,如下所示:
Header set Access-Control-Allow-Origin "*"
Be sure that you enabled mod_headers in your apache server. 确保在apache服务器中启用了mod_headers 。
For customizing access you can use something like https://stackoverflow.com/a/10605009/5397119 . 要自定义访问权限,您可以使用https://stackoverflow.com/a/10605009/5397119之类的内容 。
See also https://stackoverflow.com/a/22331450/5397119 另请参见https://stackoverflow.com/a/22331450/5397119
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.