Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- $GOOGLE_URL = "http://www.google.com";
- $GOOGLE_SBI_URL = "/searchbyimage?image_url=";
- $IMAGE_URL = your_image_folder_url; // the folder where your images are
- $IMAGE_URL_ENCODED = your_image_folder_url_percent_encoded; // change the dashes and dots to % things
- $IMAGE_SUFFIX = $_GET['imgsfx']; // gets the image file name from the PHP call
- // your browser info goes here. might be different. got mine from here: http://whatsmyuseragent.com/
- $AGENT_ID = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.101 Safari/537.11";
- $url .= $GOOGLE_URL;
- $url .= $GOOGLE_SBI_URL;
- $url .= $IMAGE_URL_ENCODED;
- $url .= $IMAGE_SUFFIX;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_USERAGENT, $AGENT_ID);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $body = curl_exec($ch);
- curl_close($ch);
- // link matchstring gets all the image links
- $linkmatchstring = "/imgres\?imgurl\=(.*?)(\&|\%3F)/";
- // thumb match string gets the base64 byte data that it uses for thumbnails
- $thumbmatchstring = "/'imgthumb1','data:image\/jpeg;base64,(.*?)'\)/";
- // regex match on the curl text
- preg_match_all($linkmatchstring, $body, $linkmatches);
- preg_match_all($thumbmatchstring, $body, $thumbmatches);
- // matches come in arrays
- $linkoutput = $linkmatches[1][0];
- $thumboutput = $thumbmatches[1][0];
- $filename .= "gimgcurldump";
- $filename .= $IMAGE_SUFFIX;
- $filename .= ".html";
- $f = fopen($filename,"w");
- // makes a new html page
- $htmloutput .= "<html>\n<head>\n</head>\n<body>\n<img src=\"";
- $htmloutput .= $IMAGE_URL;
- $htmloutput .= $IMAGE_SUFFIX;
- $htmloutput .= "\"/>\n";
- $htmloutput .= "<img src=\"";
- $htmloutput .= $linkoutput;
- $htmloutput .= "\"/>\n</body>\n</html>";
- fwrite($f,$htmloutput);
- fclose($f);
- // This is where I was trying to get stuff back.
- //HttpResponse::setData($file);
- //HttpResponse::send();
- echo($thumboutput);
- //echo($file);
- ?>
Add Comment
Please, Sign In to add comment