web image to mysql via PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
acee12345
Forum Newbie
Posts: 2
Joined: Wed Sep 22, 2010 7:56 am

web image to mysql via PHP?

Post by acee12345 »

Purpose:
The following is some very rough code in the attempt to grab images off google search and shove them in a mysql database.

State of code:
So far code works to the point that it will grab images and put the URL in the database then display the images(not extracted from database).

Need:
I would like to put the images themselves in the database but cannot find a successful way to do so. Any help is greatly appreciated.

Code: Select all

 <?php
		
			// get list of images from google images
			 // Create MySQL login values and 
		// set them to your login information.
		$username = "*******";
		$password = "**********";
		$host = "*******";
		$database = "binary";
		
		// Make the connect to MySQL or die
		// and display an error.
		$link = mysql_connect($host, $username, $password);
		if (!$link) {
			die('Could not connect: ' . mysql_error());
		}
		
		// Select your database
		mysql_select_db ($database);  
			
			
		$k='*****some query****';
		$url = "http://www.google.com/images?hl=en&source=imghp&biw=1920&bih=859&q=##query##&gbv=2&aq=f&aqi=g10&aql=&oq=&gs_rfai=";
		$web_page = file_get_contents( str_replace("##query##",urlencode($k), $url ));

		$tieni = stristr($web_page,"dyn.setResults(");
		$tieni = str_replace( "dyn.setResults(","", str_replace(stristr($tieni,");"),"",$tieni) );
		$tieni = str_replace("[]","",$tieni);
		$m = preg_split("/[\[\]]/",$tieni);
		$x = array();
		for($i=0;$i<count($m);$i++) {
			$m[$i] = str_replace("/imgres?imgurl\\x3d","",$m[$i]);
			$m[$i] = str_replace(stristr($m[$i],"\\x26imgrefurl"),"",$m[$i]);
			$m[$i] = preg_replace("/^\"/i","",$m[$i]);
			$m[$i] = preg_replace("/^,/i","",$m[$i]);
			if ($m[$i]!="")
			{
				$tmpName = $m[$i];
				
				// Create the query and insert
				// into our database.
				$query = "INSERT INTO tbl_images ";
				$query .= "(image) VALUES ('$tmpName')";
				$results = mysql_query($query, $link);
				//
				echo "<img src='".$m[$i]."' />";
				array_push($x,$m[$i]);
			}
			
		}
            $ar = $x;
        ?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: web image to mysql via PHP?

Post by requinix »

Pretty sure you're not allowed to be doing this.

What's it for, anyways?
acee12345
Forum Newbie
Posts: 2
Joined: Wed Sep 22, 2010 7:56 am

Re: web image to mysql via PHP?

Post by acee12345 »

tasairis wrote:Pretty sure you're not allowed to be doing this.

What's it for, anyways?
Google isn't the intended target, just common ground so others can help me out if need be. Intended use is neural network training at a university. My need is just to deal with an url image to a database.

As as far as what is allowed:

This is far from a final draft. I just need a set in the beginning to work out the network and make sure its learning correctly. After that gets going I will not need to keep the files just scan and extract characteristics and spider the attached page. I do not think that breaks any laws nor did I agree to any terms of use with Google.

Legality:
Law only stipulates that spiders follow the robot.txt I'm assuming Google wouldn't make such a large blunder as to open themselves up to law suits on such a grand scale as to ignore that. In this instance I'm assuming that if there was a breach I would not be the largest offender nor the one with deepest pockets. Secondly, the data this will be intercepting is all beyond a University firewall at which point the University has free access to anything.

I do not mean to come off overly aggressive but I can only see the following: "Pretty sure you're not allowed to be doing this." as unhelpful.
Post Reply