Jump to content

Recommended Posts

Greetings,

I've been looking for an easy way to download images from google images using a php script.  I happened upon one such script but upon running it I recieve the following error;

imgurl="+(b.b.indexOf("://")<0?"http://":"")+b.b+" FAILED  ???

I'm running PHP 5 in windows vista as well as in Ubuntu 7 and recieve the same error.

I was hoping someone could look at the script and tell me why the error is occuring. I've already tried contacting the author but had no response. Your assistance would be greatly appreciated.

Regards

John

 

#!/usr/bin/php

<?php

$PROGRAMNAME="PGID";

$VERSION="0.99.1";

$DEBUG=0;

$DIR_BASE=getcwd();

$FILE_HTML="temp.html";

$NPERPAG=20;

$MAXDOWNLOAD=20;

 

$SURL="http://images.google.com/images?q=";

function WRITE_DEBUG($str) {

  global $DEBUG;

  if ($DEBUG==1) {

    echo "DEBUG :$str\n";

  }

}

 

function writeFile($nameFile, $str) {

  WRITE_DEBUG("--$nameFile--");

  $file = fopen($nameFile, 'w');

  fwrite($file, $str);

  fclose($file);

}

 

 

function WgetFile($URL, $dir, $root) {

  $namefile=$dir."/".$root.basename($URL);

  if (@copy($URL, $namefile)) {

          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];

// Create the Save Directory

$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);

}

$end=false;

$start=0;

$amount=0;

while (!$end) { //Process Temporary Result Page

  $scontent = file_get_contents($SURL.$keyword."&start=".$start);

  $start=$start+$NPERPAG;

  writeFile($DIR_BASE."/".$FILE_HTML, $scontent);

  if ($scontent) {

    WRITE_DEBUG($scontent."\n");

  } else {

    echo "error\n";

  }

  $PATTERN ="((imgurl=[^\&]*)+)";

  $pos=0;

  $i=0;

  while ($len=ereg($PATTERN, $scontent, $return)) {

    $i++;

    $amount++;

    if ($i>$NPERPAG) {

      die();

    }

    $pos=strpos($scontent, "imgurl=");

    //echo $pos."\n";

    echo $return[1]."";

    $pos=$pos+$len;

    //echo $pos."\n";

    $scontent=substr($scontent,$pos);

    $url = substr($return[1], 7);

    WgetFile($url,$dir_save, substr("000".$amount, strlen($amount))."_" );

    //writeFile($DIR_BASE."/".$i.$FILE_HTML, $scontent);

    //$scontent=$scontent;

  }

  if ($i<$NPERPAG) {

    $end=true;

  }

  if ($start==$MAXDOWNLOAD) {

    $end=true;

  }

}

echo "DONE\n";

 

?>

 

Link to comment
https://forums.phpfreaks.com/topic/63401-google-image-dwnloader/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.