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); } Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
scarhand Posted September 9, 2009 Author Share Posted September 9, 2009 I had a path wrong. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.