Sending PHP files to new sites

[php]<?PHP
session_start();
require(‘config.php’);

// Generating url for api request
$url = APIURL;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
if( !empty($_POST[‘posted’]) ){
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
}
if (!($contents = trim(@curl_exec($ch)))) {
$contents = trim(file_get_contents($url));
}
curl_close ($ch);

echo $contents;
?>[/php]

I have this block of PHP for my index page and it generates and creates my pages for that particular site. It writes files and copies images to my directory where the PHP file is. I use the copy and unlink functions to move my files & images between the folders, and it all works great.

Now I want to take it a step further. Is there a way to save the files that are being written to the new domain? My current problem is that when I place the index file on my new domain, the files get generated where the API file is. Overall, how can I get the files to be saved to the new domain root folder.

Best Regards,
Josh

Well, not sure about the CURL code you posted, but, normally, you can save a file to another site if you have write permissions to it or if it is on the same server. Usually, you just add the correct “steering” to the folder you want.

So, if the filename is in $filename, you would add in a folder name in front of it.
$filename = “somefolder/somesubfolder/” . $filename;
Then, save the file…

Sometimes on the same server you will have one site in a folder and at the same level have a second site in another folder. www.mydomain.com/site1/index.php and www.mydomain.com/site2/index.php
In this case if you are in site one, you would just use something like this to get to site2’s folders…
$filename = “…/site2/somefolder/somesubfolder/” . $filename

Not sure if that is what you wanted… If you are talking about two different domains, you might have to use FTP (inside PHP) because some hosting servers do not allow cross-domain posting of files. This is a security issue. But, hope that is what you were looking for! Good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service