Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. <?php
  2. function savePhoto($remoteImage, $isbn) {
  3.     $ch = curl_init();
  4.     curl_setopt ($ch, CURLOPT_URL, $remoteImage);
  5.     curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  6.     curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
  7.     $fileContents = curl_exec($ch);
  8.     curl_close($ch);
  9.     $newImg = imagecreatefromstring($fileContents);
  10.     return imagejpeg($newImg, "./photos/{$isbn}.jpg",100);
  11. }
  12. function rand_str($length = 32, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890')
  13. {
  14.     $chars_length = (strlen($chars) - 1);
  15.     $string = $chars{rand(0, $chars_length)};
  16.     for ($i = 1; $i < $length; $i = strlen($string))
  17.     {
  18.         $r = $chars{rand(0, $chars_length)};  
  19.         if ($r != $string{$i - 1}) $string .=  $r;
  20.     }  
  21.     return $string;
  22. }
  23. $fileURL = $_POST['filadress'];
  24. savePhoto($fileURL, rand_str());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement