Created
June 30, 2016 04:33
-
-
Save waleedahmad/e720cda70b6f627be94da360fcea5ed8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function generateRandomString($length = 10) { | |
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
$charactersLength = strlen($characters); | |
$randomString = ''; | |
for ($i = 0; $i < $length; $i++) { | |
$randomString .= $characters[rand(0, $charactersLength - 1)]; | |
} | |
return $randomString; | |
} | |
if ($_FILES['image']['size'] == 0 && $_FILES['image']['error'] == 4){ | |
$uri = "/uploads/0.jpg"; | |
}else{ | |
$rand = generateRandomString(); | |
$path = $_SERVER['DOCUMENT_ROOT'] . "/uploads/" . $rand.basename($_FILES['image']['name']); | |
$uri = "/uploads/" .$rand.basename($_FILES['image']['name']); | |
move_uploaded_file($_FILES["image"]["tmp_name"], $path); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment