Re: FOPEN For Getting Images From Another Site
| From: | Jeff Gannaway | Date: | Thu, 13 Jul 2000 13:02:17 +0000 |
| Subject: | Re: FOPEN For Getting Images From Another Site | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-6515@lists.php.net to get a copy of this message | ||
In answer ot my question "How do I load an image from another site and save
it onto mine", Matthew Leverton wrote:
>It should be possible, but the reason it doesn't work for you is because the
>"filesize" doesn't work on URLs. Try this:
>
>$fcontents = join( '', file(
>'http://www.php.net' ) );
>
It worked with text files, but didn't work with images.
I also tried using your fread example without the script working at all.
This is the best I've been able to do:
<?
$filename = "http://www.theirsite.com/auctions/acdc.jpg";
$fp = fopen("$filename", "rb");
$fcontents = fread($fp, 5000000);
$fp2 = fopen ("/home/mysite/www/public/test.jpg", "wb", strlen($fcontents));
fwrite ($fp2, $fcontents);
print "<img src=\"http://www.mysite.com/public/test.jpg\">";
fclose($fp);
fclose($fp2);
?>
The above routine copies the .jpg from their site and saves it in my public
directory. They have both have the smae filesize, and when I look at both
files in NOTEPAD, all the goofy characters match up perfectly (as far as I
can tell). That would seem to indicate that it worked, but when i try to
call up the image, it comes up invalid. I've also tried looking at it in a
graphics program without any sucess.
BTW, I've tried the $fp2 = fopen line both with and without the
strlen($fcontents) parameter and the filesize comes out identical either way.
Help,
Jeff