Wireless102 Posted April 21, 2007 Share Posted April 21, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/48040-solved-curl-problems-getting-file/ Share on other sites More sharing options...
Wireless102 Posted April 22, 2007 Author Share Posted April 22, 2007 using the ltrim function fixed the problem, the url of the file had a space at the beginning of it Quote Link to comment https://forums.phpfreaks.com/topic/48040-solved-curl-problems-getting-file/#findComment-235060 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.