Created
July 20, 2014 02:35
-
-
Save mkotb/4d96100d662a44ae63a2 to your computer and use it in GitHub Desktop.
PHP Script
This file contains hidden or 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 | |
// Path at-which you want to store your images in | |
$path = '/home/mazentheamazin/public_html/'; | |
// The URI path at which images will be accessed (change as necessary). | |
$uri = 'http://' . $_SERVER['HTTP_HOST'] . '/'; | |
if ($_FILES["file"]["error"] == UPLOAD_ERR_OK) { | |
$tmp_name = $_FILES["file"]["tmp_name"]; | |
//set the random id length | |
$random_id_length = 16; | |
//generate a random id encrypt it and store it in $rnd_id | |
$rnd_id = crypt(uniqid(rand(),1)); | |
//to remove any slashes that might have come | |
$rnd_id = strip_tags(stripslashes($rnd_id)); | |
//Removing any . or / and reversing the string | |
$rnd_id = str_replace(".","",$rnd_id); | |
$rnd_id = strrev(str_replace("/","",$rnd_id)); | |
//finally I take the first 10 characters from the $rnd_id | |
$rnd_id = substr($rnd_id,0,$random_id_length); | |
move_uploaded_file($tmp_name, "$path$rnd_id" . '.png'); | |
echo $uri, $rnd_id . '.png'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment