/    Sign up×
Community /Pin to ProfileBookmark

Copy from one domain to another – getting error

When I run this code:

[code=php]
if(!@copy(‘http://www.choicenator.com/ajax/selectcontender.js’,’/home/$user/public_html/$shop/ajax/selectcontender.js’))
{
$errors= error_get_last();
echo “COPY ERROR: “.$errors[‘type’];
echo “<br />n”.$errors[‘message’];
} else {
echo “File copied from remote!”;
}[/code]

I am getting this error:

[QUOTE]

COPY ERROR: 2
copy(/home/magnif9/public_html/$shop/ajax/selectcontender.js) [function.copy]: failed to open stream: No such file or directory

[/QUOTE]

You can copy and paste the file source and see that it is the correct location. I have set the file permissions to 777. Any ideas?

Thanks,
Chris

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ilbonparaurtiMay 03.2010 — I highly suggest using cURL. Something along the lines of:

[code=php]
function fetch_url( $url )
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, USER_AGENT );
curl_setopt( $ch, CURLOPT_HTTPGET, 1 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION , 1 );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION , 1 );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_REFERER, NULL );
$contents = curl_exec($ch);
curl_close($ch);

return $contents;
}

$localFile = "/home/$user/public_html/$shop/ajax/selectcontender.js";
$remoteFile = 'http://www.choicenator.com/ajax/selectcontender.js';

$contents = fetch_url($remoteFile);
$handle = fopen( $localFile, 'w' );
fwrite($handle, $contents);
fclose($handle);
[/code]
×

Success!

Help @cdoor84 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...