quasiman Posted June 16, 2009 Share Posted June 16, 2009 Hello all... I'm trying to download a ton of images from my ftp site, and all I'm getting are blank (1kb) images. The images are named with the same SKU ID as the products in the database, so I'm looping through the mysql table for each of the matching products. Obviously limit=10 because I don't want this running forever without it working right. Hopefully someone can look at this and tell me what I'm doing wrong?? Please <?php function GetImageFromUrl($link,$filename) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 0); curl_setopt($ch,CURLOPT_URL,$link); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result=curl_exec($ch); curl_close($ch); return $result; } mysql_connect("localhost", "admin", "password") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); $result = mysql_query("SELECT * FROM products LIMIT 10") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { $path = "ftp://ftp.productimages.server.com"; $filename = $row['product_sku'] . ".jpg"; $img = $path."/".$filename; $contents = GetImageFromUrl($img, $filename); $savefile = fopen($filename, 'w'); fwrite($savefile, $contents); fclose($savefile); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/162351-solved-curl-mysql-fopen-blank-image/ Share on other sites More sharing options...
Jibberish Posted June 16, 2009 Share Posted June 16, 2009 try using the b flag in fopen $savefile = fopen($filename, 'wb'); Quote Link to comment https://forums.phpfreaks.com/topic/162351-solved-curl-mysql-fopen-blank-image/#findComment-856936 Share on other sites More sharing options...
quasiman Posted June 16, 2009 Author Share Posted June 16, 2009 Nope, same thing...10 blank files generated. Quote Link to comment https://forums.phpfreaks.com/topic/162351-solved-curl-mysql-fopen-blank-image/#findComment-857252 Share on other sites More sharing options...
premiso Posted June 16, 2009 Share Posted June 16, 2009 Have you tested the variables, such as $img and verified that you are able to view that url? It could be as simple as the url is not found or a small typo or a missed directory. Quote Link to comment https://forums.phpfreaks.com/topic/162351-solved-curl-mysql-fopen-blank-image/#findComment-857264 Share on other sites More sharing options...
quasiman Posted June 16, 2009 Author Share Posted June 16, 2009 oh brother....lol that did it. My FTP Address wasn't formatted right. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/162351-solved-curl-mysql-fopen-blank-image/#findComment-857275 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.