"; exit; } // Get the names and sort them. The !== prevents php from thinking the // items are equal if you use another name which counts a false (such as // zero or the empty string.) 0 !== false is true, but 0 != false is false. $names = array(); while (($file = readdir($dp)) !== false) { if($file == '.' || $file == '..') continue; $names[] = $file; } closedir($dp); if(count($names) >= MAXNUM) $message = "The remote directory is full"; if(count($names) == 0) $message = "The remote directory is empty"; // Try to read the sent file. // echo "$oper $userfile $userfile_name"; if($oper == 'Send' && $_FILES['sentfile']) { // This is convenient. $fn = $_FILES['sentfile']['name']; // Get the local name. $newname = $_REQUEST['newname']; if(!$newname) $newname = preg_replace('/^.*[\\/\\\\]/', '', $fn); if($_FILES['sentfile']['error'] != UPLOAD_ERR_OK) switch($_FILES['sentfile']['error']) { case UPLOAD_ERR_INI_SIZE: $message = "File $fn exceeds system max size."; break; case UPLOAD_ERR_FORM_SIZE: $message = "File $fn is too large."; break; case UPLOAD_ERR_PARTIAL: $message = "$fn upload was not completed."; break; case UPLOAD_ERR_NO_FILE: $message = "No file uploaded."; break; case UPLOAD_ERR_NO_TMP_DIR: case UPLOAD_ERR_CANT_WRITE: $message = "Unable to create temp copy of $fn" . ' (server error)'; break; default: $message = "Upload failed."; } else if(count($names) >= MAXNUM) $message = "The file repository is full."; else if($_FILES['sentfile']['size'] > MAXSIZE) $message = "File $fn is too large."; else if(!preg_match('/^[a-zA-Z0-9_\\.-]+$/', $newname)) // Allowing only alnums and a few others. $message = "File name $newname is not allowed."; else if(array_search($newname, $names)) $message = "File $newname already exists."; else { // Trim the file name, then move the file. if(!@move_uploaded_file($_FILES['sentfile']['tmp_name'], DIR."/$newname")) $message = "File system copy failed."; // Not in the directory listing. Fix. $names[] = $newname; if(count(names) == 1) $message = ''; } } // Error msg, if any. if($message) echo '',"$message
";
// File upload entry. Omit if the directory is full
if(count($names) < MAXNUM)
{
// File upload form. Much copied from PHP doc.
$maxsize = MAXSIZE;
$me = $_SERVER['PHP_SELF'];
echo <<File List
';
echo "\n";
echo '
\n";
?>
';
sort ($names);
reset ($names);
foreach($names as $fn) {
echo "', gen_link('ref', '[Refresh]'), ' ";
echo ' ', gen_link('del', '[Delete]', $fn),
' ';
echo '', gen_link('dld', '[Get]', $fn),
' ';
echo ' ', $fn, ' ';
echo '';
}
echo "