scarhand Posted September 9, 2009 Share Posted September 9, 2009 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 More sharing options...
Garethp Posted September 9, 2009 Share Posted September 9, 2009 Why not use GD2 to load an external image and save it locally? Link to comment https://forums.phpfreaks.com/topic/173642-solved-fwrite-remote-image-not-working/#findComment-915295 Share on other sites More sharing options...
PFMaBiSmAd Posted September 9, 2009 Share Posted September 9, 2009 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. Link to comment https://forums.phpfreaks.com/topic/173642-solved-fwrite-remote-image-not-working/#findComment-915300 Share on other sites More sharing options...
scarhand Posted September 9, 2009 Author Share Posted September 9, 2009 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. Link to comment https://forums.phpfreaks.com/topic/173642-solved-fwrite-remote-image-not-working/#findComment-915305 Share on other sites More sharing options...
scarhand Posted September 9, 2009 Author Share Posted September 9, 2009 I had a path wrong. Link to comment https://forums.phpfreaks.com/topic/173642-solved-fwrite-remote-image-not-working/#findComment-915315 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.