Copy .png file from external server to webserver
Posted: Fri Nov 05, 2010 2:07 pm
I'm trying to copy a .png image file from an external server to use on my server. This is because certain browsers don't like me pulling in info from domains that are not part of the current domain structure. But every method i've tried gives me a stream error: failed to open stream: Connection timed out in...yada yada yada
I've chaned the folder i'm trying to copy to, to chmod 777. I've run phpinfo() and safe_mode is off and allow_url_fopen is on. still nothing. Below are some of the things i've tried.
I've chaned the folder i'm trying to copy to, to chmod 777. I've run phpinfo() and safe_mode is off and allow_url_fopen is on. still nothing. Below are some of the things i've tried.
Code: Select all
<?php
function LoadPNG($imgname)
{
//Attempt to open
$im = @imagecreatefrompng($imgname);
//See if it failed
if(!$im)
{
//Create a blank image
$im = imagecreatetruecolor(150, 30);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
//Output an error message
imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
}
return $im;
}
header('Content-Type: image/png');
$img = LoadPNG('http://www.somesite.com:81/folder/some.png');
imagepng($img);
imagedestroy($img);
?>Code: Select all
<?php copy('http://www.somesite.com:81/folder/some.png', 'some_image/some.png'); ?>Code: Select all
<?php
header("Content-type: image/png");
$im = imagecreatefrompng("http://www.somesite.com:81/folder/some.png");
imagepng($im, 'some_image/some.png');
imagedestroy($im);*/
?>Code: Select all
<?php
function copyFile($url,$dirname){
@$file = fopen ($url, "rb");
if (!$file) {
echo"<font color=red>Failed to copy $url!</font><br>";
return false;
}else {
$filename = basename($url);
$fc = fopen($dirname."$filename", "wb");
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;
}
}
copyFile("http://www.somesite.com:81/folder/some.png","some_image/some.png");
?>