Skip to content

Instantly share code, notes, and snippets.

@necenzurat
Forked from mihneawalker/dloader.php
Created December 27, 2011 14:31
Show Gist options
  • Save necenzurat/1523818 to your computer and use it in GitHub Desktop.
Save necenzurat/1523818 to your computer and use it in GitHub Desktop.
downloader
<?php
$fsource = fopen('x.txt','r');
function save_image($img,$fullpath){
$ch = curl_init ($img);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec($ch);
curl_close ($ch);
if(file_exists($fullpath)){
unlink($fullpath);
}
$fp = fopen($fullpath,'x');
fwrite($fp, $rawdata);
fclose($fp);
}
while (!feof($fsource)) {
$fline = fgetcsv($fsource,1000,',');
$remotePath = $fline[0];
$localfname = ucwords($fline[1]);
$localfname = preg_replace("/[^a-zA-Z0-9s]/","",$localfname);
$xtn = pathinfo($remotePath, PATHINFO_EXTENSION);
$localfname ='pics/' . $localfname . '-'. rand(1,99) . '.'.$xtn;
//var_dump($localfname);
save_image ("$remotePath","$localfname");
echo "done $remotePath\n";
//exec("wget -O $localfname $remotePath");
}
echo "done";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment