Advertisement
Guest User

Untitled

a guest
Feb 8th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.37 KB | None | 0 0
  1. <?php
  2.  
  3. function download($link)
  4. {
  5.     $ch = curl_init();  
  6.     curl_setopt($ch, CURLOPT_URL, $link);  
  7.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  8.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  9.     curl_setopt($ch, CURLOPT_HEADER, 0);  
  10.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
  11.     $output = curl_exec($ch);  
  12.     curl_close($ch);
  13.     return $output;
  14. }
  15.  
  16. include('cfg.php');
  17.  
  18. $db = new mysqli($mysql_hostname, $mysql_username, $mysql_password, $mysql_dbname);
  19.  
  20. $gid = $_GET['gid'];
  21. $aid = $_GET['aid'];
  22. $offset = 0;
  23. $cnt = 0;
  24. while (1)
  25. {
  26.     $contents = download('https://api.vk.com/method/photos.get?owner_id=-'.$gid.'&album_id='.$aid.'&offset='.$offset);
  27.     $contents = json_decode($contents, true);
  28.     $input = $contents['response'];
  29.  
  30.     if (count($input) == 0)
  31.         break;
  32.    
  33.     for ($i=0; $i<count($input); $i++)
  34.     {
  35.         $pid = $input[$i]['pid'];
  36.         $user_id = $input[$i]['user_id'];
  37.        
  38.         if ($user_id == 100)
  39.             continue;
  40.        
  41.         $group_id = $gid;
  42.         $src = $input[$i]['src_big'];
  43.         if (isset($input[$i]['src_xbig']))
  44.             $src = $input[$i]['src_xbig'];
  45.         if (isset($input[$i]['src_xxbig']))
  46.             $src = $input[$i]['src_xxbig'];
  47.        
  48.         $stmt = $db->prepare("INSERT INTO main VALUES(?,?,?,?)");
  49.         $stmt->bind_param('ddds', $pid, $user_id, $group_id, $src);
  50.  
  51.         $stmt->execute();
  52.         $stmt->close();
  53.        
  54.         echo $cnt."<br>";
  55.         $cnt++;
  56.     }
  57.    
  58.     $offset += count($input);
  59. }
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement