- Code: Selecteer alles
<?php
function downloadImagesGoogle($criteria, $map){
$search = str_replace(' ','+',$criteria);
$images = array();
$return = array();
$dom = new DOMDocument();
@$dom->loadHtmlFile('http://www.google.nl/images?q='.$search.'&biw=1220&bih=994');
$xpath = new DOMXPath( $dom );
$links = $xpath->query( '//img' );
foreach ( $links as $link )
{
$expl= explode(':', $link->getAttribute( 'src' ));
if(isset($expl[3])){
$images[] = $expl[3].':'.$expl[4] ;
}
}
$dom = NULL ;
if(!file_exists($map)){
mkdir($map);
}
if(count($images) > 0){
for($i = 0; $i < count($images); $i++){
if(isset($images[$i])){
$explode = explode('.',$images[$i]);
$extension = $explode[(count($explode)-1)];
if($extension == 'jpg' || $extension == 'jpeg'){
if($img = file_get_contents($images[$i])){
$return[$i] = 'images/'.$map.'/'.$i.'.'.$extension ;
file_put_contents($return[$i],$img);
$done++ ;
}
}
}
}
}
if(count($return) > 0){
return $return ;
}else{
return false ;
}
}
?>