Jump to content

[SOLVED] curl, mysql, & fopen = blank image


quasiman

Recommended Posts

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 ;D

<?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);
}
?>

Link to comment
https://forums.phpfreaks.com/topic/162351-solved-curl-mysql-fopen-blank-image/
Share on other sites

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.