Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Googled Downloading Images with cURL/Php and Adapted
- $img[]='http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=10&size=600x600&maptype=hybrid&sensor=false';
- $img[]='http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=11&size=600x600&maptype=hybrid&sensor=false';
- $img[]='http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=12&size=600x600&maptype=hybrid&sensor=false';
- $img[]='http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=13&size=600x600&maptype=hybrid&sensor=false';
- $img[]='http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=14&size=600x600&maptype=hybrid&sensor=false';
- $img[]='http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=15&size=600x600&maptype=hybrid&sensor=false';
- $img[]='http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=16&size=600x600&maptype=hybrid&sensor=false';
- $img[]='http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=17&size=600x600&maptype=hybrid&sensor=false';
- $img[]='http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=18&size=600x600&maptype=hybrid&sensor=false';
- $img[]='http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=19&size=600x600&maptype=hybrid&sensor=false';
- $img[]='http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=20&size=600x600&maptype=hybrid&sensor=false';
- $img[]='http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=21&size=600x600&maptype=hybrid&sensor=false';
- 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>';
- }
- }
- //Alternative Image Saving Using cURL seeing as allow_url_fopen is disabled - bummer
- 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);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement