Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.