//Uploader by Dylan Johnston
//Make sure to CHMOD your upload dir to 777 or whatever.
$site = "http://yoursite/"; //your site with trailing slash.
$updir = "uploads"; //upload folder without trailing slash.
$thisfile = "u.php";
$back = "Go Back"; // your message :D
if (isset($_POST["submit"]) && $_POST["submit"] == "UPLOAD") {
function generate_rand($l){
$c= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
for($i=0; $i<$l; $i++) {
$rand.= $c[rand()%strlen($c)];
}
return $rand;
}
$uploaddir = $updir . "/";
$maxfilesize = 10485760; //10MB?
$filename = $_FILES['file']['name'];
$filesize = $_FILES['file']['size'];
$filetmpname = $_FILES['file']['tmp_name'];
$valid = array (".zip", ".png", ".bmp"); // Your allowed file types.
if ($filename) {
$error = "";
if ($filesize == 0) {
$error .= "Invalid File $back";
}
$type = strtolower( strstr( $filename, '.' ) );
if ( !in_array( $type, $valid ) ) {
$error .= "Unsupported FileType $back";
}
if ($filesize>$maxfilesize) {
$error .= "File was too big
$back";
}
$randnum = generate_rand(10);
$randnum .= $type;
$file_exists = true;
while ($file_exists) {
if (file_exists("$uploaddir$randnum")) {
$randnum = generate_rand(10);
$randnum .= $type;
}else{
$file_exists = false;
}
}
if ($error == "") {
if (move_uploaded_file($filetmpname, "$uploaddir$randnum")) {
chmod("$uploaddir$randnum", 0644);
echo "Success
";
echo "$site$updir/$randnum
";
echo "$back";
} else {
echo "Error $back";
}
}else{
echo $error;
}
}else{
echo "Error $back";
}
}else{
?>