Error:
Expand|Select|Wrap|Line Numbers
- failed to open stream: Permission denied in
[PHP]
function wwwcopy($url,$dirname){
$file = fopen($url, "r");
if (!$file) {
echo"<font color=red>Failed to copy $url!</font><br>";
return false;
}else {
$fc = fopen("$dirname", "w");
while (!feof ($file)) {
$line = fread ($file, 1028);
fwrite($fc,$line);
}
fclose($fc);
echo "<font color=blue>File $url saved to PC!</font><br>";
return true;
}
}
[/PHP]
I have checked my php.ini settings and my folder/file permissions seem to be set right so i dont know if my host is restricting me or whats up.
Expand|Select|Wrap|Line Numbers
- allow_url_fopen = On
*NOTE files hosted on the same server I can copy just not stuff on other servers and thats what i want this code for. This code is meant to copy IMAGES.
But I have also started the cURL code but can't seem to get it working, all i get is a file that contains text! ex. http://someothersite.com/images/image.gif i dont really no anything about cURL and i'm a total noob at php so any help would be appreciated.
[PHP]function wwwcopy($address,$dirname){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $address);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
echo $data;
$FileName = $dirname;
$fh = fopen($FileName, 'w') or die("can't open file");
fwrite($fh, $data);
fclose($fh);}[/PHP]