Jump to content

[SOLVED] fwrite remote image not working


scarhand

Recommended Posts

im trying to get an image from a remote URL and write it to a local folder

 

now it gets the image, but the image is always corrupt....

 

code:

 

$sql = mysql_query("select * from prods order by id asc limit 1");

while ($row = mysql_fetch_assoc($sql))
{
  $imgo = $row['img'];
  $imgo = str_replace('product/', '', $imgo);
  $imgu = "http://www.imgsite.com/$img";
  
  $content = file_get_contents($imgu);
  $dir = dirname($_SERVER['SCRIPT_FILENAME']) . '/img';
  $fp = fopen($dir . '/' . $imgo, 'w');
  
  fwrite($fp, $content);
  fclose($fp);
}

Link to comment
https://forums.phpfreaks.com/topic/173642-solved-fwrite-remote-image-not-working/
Share on other sites

How do you know it is corrupt? How are you attempting to open or display it? Is the resulting file the expected size? Smaller? Larger? Have you opened the file using a programming editor to examine what it actually contains?

 

The GD functions should not be used just to "copy" an image. They take a huge amount of resources and processing time because they operate on an uncompressed bitmap version of the image. You also need to know or find the image type before you can use the correct functions.

How do you know it is corrupt? How are you attempting to open or display it? Is the resulting file the expected size? Smaller? Larger? Have you opened the file using a programming editor to examine what it actually contains?

 

The GD functions should not be used just to "copy" an image. They take a huge amount of resources and processing time because they operate on an uncompressed bitmap version of the image. You also need to know or find the image type before you can use the correct functions.

 

I opened the file in internte explorer and its a red X. I opened it in windows photo gallery and it tells me "the image is damaged or corrupted".

 

But the image is the same size as the one I used fwrite on.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.