|
Post by me3you2 on Mar 2, 2006 1:00:54 GMT -5
I need help finding a program that will goto a site and download a list of images based on the file name. Not just the extension but the name its'self. If anyone can help let me know.
It can be a windows app, PHP, or something like that.
|
|
sdphantom
Full Member
Savior and Destroyer
Posts: 230
|
Post by sdphantom on Mar 2, 2006 2:31:12 GMT -5
Here's a PHP script I wrote a long time ago. It still has some debug features left in it from when I was testing it. I know it's not exactly what you asked, but it's the closest thing I had. imgext.php <?php // ----- Config $imgextlist=array(".bmp",".gif",".jpeg",".jpg",".png",".tif",".tiff"); $fetchlinks=true; $fetchimages=false;
// ----- Program Code function sendPrint($str){ print $str; ob_flush(); }
function findPath($spath,$opath){ $urlarr=explode("://",$spath); $sarr=explode("/",$urlarr[1]); $oarr=explode("/",$opath); array_pop($sarr); if($oar==".."){ while($oarr[0]==".."){ array_pop($sarr); array_shift($oarr); } } return $urlarr[0]."://".implode("/",$sarr)."/".implode("/",$oarr); }
function isImgFile($path){ global $imgextlist; foreach($imgextlist as $i){ if(substr($path,-strlen($i))==$i) return true; } return false; }
function fetchImg($path){ sendPrint("Fetching image: $path ..."); $fname=$path; $fname=array_pop(explode("\\",$fname)); $fname=array_pop(explode("/",$fname)); if(!file_exists($fname)){ if(!$fin=fopen($path,"rb")) return; $fout=fopen($fname,"wb"); while($imgcode=fread($fin,32768)) fwrite($fout,$imgcode); fclose($fin); fclose($fout); } sendPrint("Done!<br>\n"); }
function parsePage($url){ if(!$fin=fopen($url,"rb")) return; $pagecode=""; while($section=fread($fin,8192)) $pagecode.=$section; fclose($fin);
$dcode=$pagecode; $dcode=str_replace("<","<",$dcode); $dcode=str_replace(">",">",$dcode); sendPrint("<pre>\n$dcode\n</pre>\n");
$pagecode=str_replace("\n","",$pagecode); $pagecode=str_replace("\r","",$pagecode);
if($fetchlinks){ $links=explode("href=\"",$pagecode); array_shift($links); foreach($links as $i=>$j) $links[$i]=array_shift(explode("\"",$j)); }
if($fetchimages){ $images=explode("src=\"",$pagecode); array_shift($images); foreach($images as $i=>$j) $images[$i]=array_shift(explode("\"",$i)); }
$imglist=array();
if($fetchlinks){ foreach($links as $i){ $path=findPath($url,$i); sendPrint("Examine: $path...<br>\n"); if(isImgFile($path)) $imglist[]=$path; } }
if($fetchimages){ foreach($images as $i){ $path=findPath($url,$i); sendPrint("Examine: $path...<br>\n"); if(isImgFile($path)) $imglist[]=$path; } }
if(count($imglist)>0) foreach($imglist as $i) fetchImg($i); }
if(isset($_GET['p'])) parsePage($_GET['p']); ?>
|
Then call the PHP script like this: imagext.php?p=<path to webpage> The script will go to the website and parse links and images according to the config settings and download all images pointed to by that page.
|
|