cURL / Mailing Lists / curl-users / Single Mail

curl-users

downloading file from a link

From: Carlo Dominguez <carlod_at_athenaeservices.com>
Date: Wed, 1 Jun 2005 10:08:39 +0800

hi,

im a newbie in using this function and PHP.. however my problem is I'm trying to download files via curl from a multiple link inside a text file..

example: (links.txt) these are the sample links inside the textfile
http://blablah/try.zip
http://383838/game.exe
http://jdjdjd/yes.ip

then i wud use a loop to retrieve all these, here's my complete code:

// set file to read
$filename = "links.txt";

// open file
$fh = fopen ($filename, "r") or die("Could not open file");

// read file
$cfolder = 0;

while (!feof($fh))
{
 $data = fgets($fh);
 $pos = strrpos($data, "/") +1;
 
 //CREATE A NEW FILE IN LOCAL DRIVE
 $dfile = "c:\\".Trim(substr($data, $pos)) ;
 
 $cfolder++;
 
 //FOR EACH DOWNLOAD CREATE A
//FOLDER LIKE DOWNLOAD_1, DOWNLOAD_2
 $cFolderName = "DOWNLOAD_".$cfolder;
 
  if (!file_exists($cFolderName)) {
    //create folder
    mkdir($cFolderName);
  }

  //extract file
  $filename=$data;
  $local_path="c:\\";
  
  $out = fopen($dfile, 'wb');
  
  $ch = curl_init();
            
  curl_setopt($ch, CURLOPT_FILE, $out);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_URL, $filename);

  curl_exec($ch);
       
  curl_close($ch);
    
 } //END LOOP

// close file
fclose ($fh);

I took this from a sample in weberdev.com, somehow i was trying to get some help from the author and he can't solve this. It downloads fine.. the 3 links above.. but it seems to me the first one in line is the one that works fine when opened like the zip file.. but the remaining links after being downloaded is either corrupt or incomplete file.

please help me???? tnx and God Bless

rgrds,
carlo
******************************************************************************
This email (which includes any files transmitted with it) is intended for the above named only. It may contain
privileged, confidential or price sensitive information. If you are not the intended recipient, please notify the
sender immediately and destroy all copies of this email, as well as deleting the email from your computer system.
This email is protected by copyright. If you are not the intended recipient, you are not entitled to use,
disclose or copy the email or rely on it in any way whatsoever.
******************************************************************************
Received on 2005-06-01