File Directory Php

$dir ="/www/servers/upload"; # your uploaded file dir, this dir require proper permission to write access
$temp ="/tmp"; # unix system temp dir
$maxsize ="40960"; # max 40 Kb
$quota = 524288; # define space quota 500 Kb
$ext = array(".p", ".php", ".php3", ".phtml", ".shtml"); # define file extension to reject
if ($userfile AND $userfile != "none") {
$total=0;
$handle=opendir($dir);
while ($file = readdir($handle)) {
if (is_file("$dir/$file")) {$total+=filesize("$dir/$file");}
}
while (list($key,$val) = each($ext)) {
if (strstr($userfile_name, $val)) {$invalidext=true;break;}
}
if ($userfile_size > $maxsize) {echo "ERR: File too large";}
elseif ($invalidext) {echo "ERR: Forbiden file extension";}
elseif ($total > $quota) {echo "ERR: Space quota exceeded";}
else {
rename("$userfile", "$temp/$userfile_name");
copy("$temp/$userfile_name", "$dir/$userfile_name");
unlink("$temp/$userfile_name");
echo "OK: File \"$userfile_name\" uploaded succesfully";
}
} else {
?>












: