<?php
include '/var/www/html/atproperties.com/includes/scriptPreamble.php';
$ln=$argv[1];
if ($ln<1000000){
echo "not a valid LN.\n";
exit;
}
$dir=substr($ln,-3);
$url="http://www.mredllc.com/photos/property/$dir/";
$page=MiscLib::curlBinary($url);
//$page=file_get_contents("mm.txt");
$page=str_ireplace(["<br>","<br />","<br />"],"\n",$page);
$matches=preg_grep("/$ln/",explode("\n",$page));
// 11634 => ' 3/26/2015  6:34 PM       100147 <A HREF="/photos/property/245/08872245_9.JPG">08872245_9.JPG</A>',
$files=array_map(function($el){
$match=[];
preg_match('/HREF="(.*?)"/',$el, $match);
return "http://www.mredllc.com/$match[1]";
}, $matches);
usort($files, function($a,$b){
$f1=preg_replace("/[^0-9]/","",substr($a,strpos($a,'_'),4));
$f2=preg_replace("/[^0-9]/","",substr($b,strpos($b,'_'),4));
return $f1>$f2;
});
foreach($files as $k=>$file) {
$i=$k+1;
echo shell_exec("wget $file -O $i.jpg");
}
