save file from outside url
| From: | Jeremiah Breindel | Date: | Fri, 06 Dec 2002 21:12:27 +0000 |
| Subject: | save file from outside url | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-127378@lists.php.net to get a copy of this message | ||
I am trying to save a dynamically generated image on an outside server to a
local file on my server using the code below:
$fc = fopen($image_filename, "wb");
$file = fopen ($image_url, "rb");
if (!$file) {
echo "<p>Unable to open remote file.\n";
exit;
}else{
while (!feof ($file)) {
$line = fread ($file, 1028);
fwrite($fc,$line);
}
}
fclose($fc);
fclose($file);
$image_filename is a locally referred to file, such as "../images/file1.png"
and $image_url is an absolute address, such as
"http://www.whatever.com/imagecreate.php".
Instead of saving when I run the script through a browser, the image
displays within the browser, and the script creates a file containing only
"427" on the server. Any ideas why or what I can do to correct this?
Jeremiah