Jump to content

[SOLVED] Curl, problems getting file


Wireless102

Recommended Posts

hello i am trying to download image files from another server (about 2000 of them).

I am using a mysql database to retrieve the file name/location.

the below code works fine but it has the file name hard coded into it.

<?php
        $a=0;
        $timevalue = substr(time(),3,11);
$photoname = $timevalue.$a.'.jpg';
$ch = curl_init("http://www.somedomain.com/images/some%20folder/some%20image%20file.jpg");
$fp = fopen($photoname, "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>

 

but when trying to get the file name from the database it does not work

 

<?php
$a=0;
while($row = mysql_fetch_array($result)){
$timevalue = substr(time(),3,11);
$photoname = $timevalue.$a.'.jpg';
$ch = curl_init($row['imagefile']);
$fp = fopen($photoname, "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
$a++;
}
?>

 

anyideas why it will not work?

the $row['imagefile'] is the exact link to the file on the remote server

Link to comment
https://forums.phpfreaks.com/topic/48040-solved-curl-problems-getting-file/
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.