Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function savePhoto($remoteImage, $isbn) {
- $ch = curl_init();
- curl_setopt ($ch, CURLOPT_URL, $remoteImage);
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
- $fileContents = curl_exec($ch);
- curl_close($ch);
- $newImg = imagecreatefromstring($fileContents);
- return imagejpeg($newImg, "./photos/{$isbn}.jpg",100);
- }
- function rand_str($length = 32, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890')
- {
- $chars_length = (strlen($chars) - 1);
- $string = $chars{rand(0, $chars_length)};
- for ($i = 1; $i < $length; $i = strlen($string))
- {
- $r = $chars{rand(0, $chars_length)};
- if ($r != $string{$i - 1}) $string .= $r;
- }
- return $string;
- }
- $fileURL = $_POST['filadress'];
- savePhoto($fileURL, rand_str());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement