Created
September 19, 2010 09:33
-
-
Save rpetrich/586617 to your computer and use it in GitHub Desktop.
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
<? | |
function genRandomString($length) { | |
$characters = '0123456789abcdefghijklmnopqrstuvwxyz'; | |
$string = ''; | |
for ($p = 0; $p < $length; $p++) { | |
$string .= $characters[mt_rand(0, strlen($characters))]; | |
} | |
return $string; | |
} | |
$filetype = $_FILES['media']['type']; | |
if ($filetype == 'image/png') | |
$filetype = '.png'; | |
else if ($filetype == 'image/jpeg') | |
$filetype = '.jpg'; | |
else | |
die('bad filetype'); | |
$filename = genRandomString(4). $filetype; | |
while (file_exists($filename)) | |
$filename = genRandomString(5). $filetype; | |
move_uploaded_file($_FILES['media']['tmp_name'], $filename); | |
echo '<mediaurl>http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']).'/'.$filename.'</mediaurl>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment