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. (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. This script is a custom upload class in php. This script is located on www.domain1.com but needs to upload the file to www.domain2.com.
My local server is a Xampp server with a simple file structure.
C:/xampp/htdocs
Domain1/uploadscript.php
Domain2/destinationfolder/
I am currently using the $_SERVER['DOCUMENT_ROOT'] function to navigate towards the other domain. 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']);
= C:/xampp/htdocs
On domain1.com
print_r ($_SERVER['DOCUMENT_ROOT']);
= /home/myname/domains/domain1/public_html/
On domain2.com
print_r ($_SERVER['DOCUMENT_ROOT']);
= /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".
The question(s)
How do I navigate towards the "domains" folder on my server? 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.
You can do this in your .htaccess like below:
Header set Access-Control-Allow-Origin "*"
Be sure that you enabled mod_headers in your apache server.
For customizing access you can use something like https://stackoverflow.com/a/10605009/5397119.
See also https://stackoverflow.com/a/22331450/5397119
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With