function get_files($dirstr)
{
$scanfiles = array();
$fh = opendir($dirstr);
while (false !== ($filename = readdir($fh)))
{
if (is_file("$dirstr/$filename")) {
array_push($scanfiles, $filename); }
}
closedir($fh);
sort($scanfiles);
return $scanfiles;
}
$count = count($_FILES['userfile']['name']);
if ($count > 0) {
$i=0;
$f=0;
while ($i < $count) {
$kbsize = (round($_FILES['userfile']['size'][$i]/1024));
$date = date("j M Y g:ia", time()+($timeoffset*3600));
$userip = $_SERVER['REMOTE_ADDR'];
if ($limitsize == 1) {
if ($_FILES['userfile']['size'][$i] > (1024*$maxsize) ) {
$toobig[$i] = "{$_FILES['userfile']['name'][$i]} is too large! the maximum file size is $maxsize kb.";
} }
if ($acceptfilter == 1) {
if (!in_array($_FILES['userfile']['type'][$i], $acceptabletypes)) {
$rejectstring = "{$_FILES['userfile']['name'][$i]} is not of the type ";
foreach ($acceptabletypes as $acceptabletype) {
$rejectstring .= "$acceptabletype or "; }
$rejectstring = substr($rejectstring, 0, -4);
$notacceptable[$i] = "$rejectstring.";
} }
if ($overwriting !== 1) {
if(file_exists("$uploaddir/{$_FILES['userfile']['name'][$i]}")) {
$alreadyexists[$i] = "a file of the name {$_FILES['userfile']['name'][$i]} already exists! overwriting is not permitted.";
} }
if (!isset($toobig[$i]) && !isset($notacceptable[$i]) && !isset($alreadyexists[$i])) {
copy($_FILES['userfile']['tmp_name'][$i], "$uploaddir/{$_FILES['userfile']['name'][$i]}");
echo "{$_FILES['userfile']['name'][$i]} uploaded successfully!
";
$f++;
$content .= "$date $userip uploads $uploaddir/{$_FILES['userfile']['name'][$i]} ($kbsize kb)\n";
}
elseif ($_FILES['userfile']['size'][$i] !== 0) {
echo "$toobig[$i] $notacceptable[$i] $alreadyexists[$i]
";
$content .= "$date $userip fails to upload $uploaddir/{$_FILES['userfile']['name'][$i]} ($kbsize kb) - $toobig[$i] $notacceptable[$i] $alreadyexists[$i]\n";
}
$i++;
}
echo "uploaded $f file(s)";
if ($makelog == 1) {
$handle = fopen("$logfile", "a");
fwrite ($handle, $content);
fclose ($handle); }
}
?>
echo "";
if ($makelog == 1) {
echo "- All File Upload attempts are recorded in our LOG.
"; }
if ($limitsize == 1) {
echo "- The Maximum File size is $maxsize KB.
"; }
if ($acceptfilter == 1) {
echo "- Acceptable File Types:
";
foreach ($acceptabletypes as $acceptabletype) {
echo "$acceptabletype
"; } }
if ($overwriting == 1) {
echo "- Over-Writing is permitted.
"; } else {
echo "- Over-Writing is not permitted.
"; }
if ($scandir == 1) {
echo "- The current Files in this directory are:
";
$files = get_files($uploaddir);
foreach ($files as $file) {
echo "$file
"; } }
echo "
";
unset($count, $acceptabletypes, $handle, $content, $date, $kbsize);
?>