<?php
// Opens a connection to a MySQL server
$connection=mysql_connect(\'localhost\', \'database_username\', \'database_password\');
if (!$connection) { die(\'Not connected : \' . mysql_error());}
// Set the active MySQL database
$db_selected = mysql_select_db(\'database_name\', $connection);
if (!$db_selected) {
die (\'Can\\\'t use db : \' . mysql_error());
}
// Select all the rows in the location table
$query = "SELECT * FROM nodes";
$result = mysql_query($query);
if (!$result){
die(\'Invalid query: \' . mysql_error());
}
while($location = mysql_fetch_array($result)){
//$img[]=\'http://maps.googleapis.com/maps/api/staticmap?center=\'.$location[\'lat\'].\',\'.$location[\'lng\'].\'&zoom=19&size=600x600&maptype=hybrid&sensor=false\';
$img[]=\'http://cbk0.google.com/cbk?output=thumbnail&w=400&h=218&ll=\'.$location[\'lat\'].\',\'.$location[\'lng\'];
}
foreach($img as $i){
save_image($i);
if(basename($i)){
echo \'<h3 style="color: green;">Image \' .basename($i) . \'Downloaded OK </h3>\';
}
else{
echo \'<h3 style="color: red;">Image \' .basename($i) . \' Download Failed</h3>\';
}
}
function save_image($img,$fullpath=\'basename\'){
if($fullpath == \'basename\'){
$fullpath = basename($img);
}
$ch = curl_init($img);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$rawdata = curl_exec($ch);
curl_close($ch);
if(file_exists($fullpath)){
unlink($fullpath);
}
$fp = fopen($fullpath.\'.png\',\'x\');
fwrite($fp, $rawdata);
fclose($fp);
}
error_reporting(E_ALL);
ini_set(\'display_errors\', 1);
?>