PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Er. Rochak Chauhan   Download Images from Google   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example File
Class: Download Images from Google
Search images on Google and download its files
Author: By
Last change:
Date: 9 years ago
Size: 893 bytes
 

Contents

Class file image Download
<?php
require('CURLQuery.php');
require(
'GoogleImageSearch.php');

if ( !empty(
$_REQUEST['q'] ) ) {

    try {
       
$google_api_key = 'YOUR_GOOGLE_API_KEY';
       
$search = new GoogleImageSearch( $google_api_key );
       
$search->q = $_REQUEST['q'];
       
$search->userip = $_SERVER['REMOTE_ADDR'];
       
$search->setSearchCount( 64 );
       
$search->sendQuery();
       
$images_urls = $search->getImagesUrl();
    }
    catch (
Exception $e ) {
        die(
$e->getMessage() );
    }

}

?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Google Image Search</title>
</head>
<body>
   
    <?php if( !empty( $images_urls ) AND is_array( $images_urls ) ) : ?>
<pre><?php print_r( $images_urls ); ?></pre>
    <?php else : ?>
<form action="" method="post">
            <input name="q" placeholder="Search term">
            <input type="submit">
        </form>
    <?php endif; ?>

</body>
</html>