pbmann Posted November 9, 2007 Share Posted November 9, 2007 I am an artist who has used a script called PGID in my work over the past year or so. It is a wonderful script that automatically downloads google images. I use the images to create photomosaics with over 40,000 tiles. The code was original written by Roberto Butti. For the past few months when I attempt to run the script I get the fallowing error: imgurl="+(b.b.indexOf("://")<0?"http://":"")+b.b+" FAILED I assume that something changed in the way google is linking to images, but have been unable to figure it out. I have a basic understanding of PHP, but have not been able to figure out what I need to do to update the code. Can anyone point me in the right direction? Thanks! #!/usr/bin/php <?php $PROGRAMNAME="PGID"; $VERSION="0.99.1"; $DEBUG=0; $DIR_BASE=getcwd(); $FILE_HTML="temp.html"; $NPERPAG=20; $MAXDOWNLOAD=60; $SURL="http://images.google.com/images?q="; function WRITE_DEBUG($str) { global $DEBUG; if ($DEBUG==1) { echo "DEBUG :$str\n"; } } function ScriviFile($NomeFile, $str) { WRITE_DEBUG("--$NomeFile--"); $file = fopen($NomeFile, 'w'); fwrite($file, $str); fclose($file); } function WgetFile($URL, $dir, $radice) { $nomefile=$dir."/".$radice.basename($URL); if (@copy($URL, $nomefile)) { echo " DONE\n"; } else { echo " FAILED\n"; } } // BEGIN ______________________________ WRITE_DEBUG($DIR_BASE); if ($argc == 1) { echo $PROGRAMNAME." v. ".$VERSION."\n"; echo "Usage : ".$argv[0]." <keyword>\n"; die(); } WRITE_DEBUG("ok : processing : ".$argv[1]); $keyword=$argv[1]; // IMPOSTO LA DIRECTORY DI SALVATAGGIO $dir_save=$DIR_BASE."/".$keyword."/"; if (file_exists($dir_save)) { WRITE_DEBUG("DIR ALREADY EXIST : $dir_save"); } else { WRITE_DEBUG("Creating dir $dir_save"); mkdir($dir_save); } $finito=false; $start=0; $quante=0; while (!$finito) { //SCARICA PIUI? PAGINE DI RISULTATI $scontent = file_get_contents($SURL.$keyword."&start=".$start); $start=$start+$NPERPAG; ScriviFile($DIR_BASE."/".$FILE_HTML, $scontent); if ($scontent) { WRITE_DEBUG($scontent."\n"); } else { echo "ERRORE\n"; } $PATTERN ="((imgurl=[^\&]*)+)"; $pos=0; $i=0; while ($len=ereg($PATTERN, $scontent, $ritorno)) { $i++; $quante++; if ($i>$NPERPAG) { die(); } $pos=strpos($scontent, "imgurl="); //echo $pos."\n"; echo $ritorno[1].""; $pos=$pos+$len; //echo $pos."\n"; $scontent=substr($scontent,$pos); $url = substr($ritorno[1], 7); WgetFile($url,$dir_save, substr("000".$quante, strlen($quante))."_" ); //ScriviFile($DIR_BASE."/".$i.$FILE_HTML, $scontenta); //$scontent=$scontenta; } if ($i<$NPERPAG) { $finito=true; } if ($start==$MAXDOWNLOAD) { $finito=true; } } echo "DONE\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/76662-pgid-php-google-image-downloader/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.