Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. <?php
  2. function rand_str($length = 32, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890')
  3. {
  4.     $chars_length = (strlen($chars) - 1);
  5.     $string = $chars{rand(0, $chars_length)};
  6.     for ($i = 1; $i < $length; $i = strlen($string))
  7.     {
  8.         $r = $chars{rand(0, $chars_length)};  
  9.         if ($r != $string{$i - 1}) $string .=  $r;
  10.     }  
  11.     return $string;
  12. }
  13.  
  14. function savePhoto($remoteImage, $isbn) {
  15.     $ch = curl_init();
  16.     curl_setopt ($ch, CURLOPT_URL, $remoteImage);
  17.     curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  18.     curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
  19.     $fileContents = curl_exec($ch);
  20.     curl_close($ch);
  21.     $newImg = imagecreatefromstring($fileContents);
  22.     return imagejpeg($newImg, "./photos/{$isbn}.jpg",100);
  23. }
  24.  
  25. $randStr = rand_str();
  26.  
  27. $fileURL = $_POST['filadress'];
  28. savePhoto($fileURL, $randStr);
  29.  
  30. $connection = mysql_connect("localhost", "root", "") or die(mysql_error());
  31. mysql_select_db("imgupload") or die(mysql_error());
  32.  
  33.     mysql_query("INSERT INTO tblimages
  34.     (imagename) VALUES('$randStr' ) ")
  35.     or die(mysql_error());
  36.     mysql_close($connection);  
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement