ParseCSV and PHP Curling

One of the things that came out of the BatchYouTubeUploader was this nifty little object class, ParseCSV, which I use to manipulate the CSV file for uploading the videos. I know it’s going to find a lot of use, and in this case, I wrote this little script to loop through a CSV and download a bunch of images. Just note you have to have allow_url_fopen set to true, as per this StackExchange post.

require("ParseCSV.php");

$csv = new ParseCSV("youtube-images.csv");
$n = 1;
foreach($csv->data as $data) {
  if(false != file_put_contents("pics/{$data['filename']}.jpg", file_get_contents($data['url']))) {
    $log = "File {$n}: Downloaded {$data['filename']} from {$data['url']}n";
  } else {
    $log = "File {$n}: Download from {$data['url']} failedn";
  }
  print $log;
  file_put_contents("output.log", $log, FILE_APPEND | LOCK_EX);
  $n++;
}
Edit this post on GitHub.

This post is part of the thread: Project: BatchYouTubeUploader - an ongoing story on this site. View the thread timeline for more context on this post.