* @version 1.0.1 (June 30, 2004) * @package AutoIndex */ class Upload { /** * Uploads all files in the $_FILES array, then echos the results. */ public function do_upload() { $uploaded_files = $errors = ''; global $request, $words, $log, $dir; foreach ($_FILES as $file_upload) { $filename = Item::get_basename($file_upload['name']); if ($filename == '') { continue; } if (DirectoryList::is_hidden($filename)) { $errors .= "
  • $filename [" . $words->__get('filename is listed as a hidden file') . ']
  • '; continue; } $filename = Url::clean_input($filename); $fullpathname = realpath($dir) . '/' . $filename; if (@file_exists($fullpathname)) { $errors .= "
  • $filename [" . $words->__get('file already exists') . ']
  • '; } else if (@move_uploaded_file($file_upload['tmp_name'], $fullpathname)) { @chmod($fullpathname, 0644); $uploaded_files .= "
  • $filename
  • "; $log -> add_entry("Uploaded file: $filename"); } else { $errors .= "
  • $filename
  • "; } } if ($errors == '') { $errors = '
    [' . $words->__get('none') . ']'; } if ($uploaded_files == '') { $uploaded_files = '
    [' . $words->__get('none') . ']'; } $str = '
    ' . '' . $words->__get('uploaded files') . ": $uploaded_files

    " . $words->__get('failed files') . ": $errors" . '

    ' . $words->__get('continue') . '.

    '; echo new Display($str); die(); } /** * @param User $current_user Makes sure the user has permission to upload files */ public function __construct(User $current_user) { if ($current_user->level < LEVEL_TO_UPLOAD) { throw new ExceptionDisplay('Your user account does not have permission to upload files.'); } } /** * @return string The HTML that makes up the upload form */ public function __toString() { global $request, $words, $subdir; if ($request->is_set_get('num_uploads') && (int)$request->get('num_uploads') > 0) { $str = '

    '; $num = min((int)$request->get('num_uploads'), 100); for ($i = 0; $i < $num; $i++) { $str .= "\n\t" . $words->__get('file') . ' '. ($i + 1) . ' :
    '; } $str .= '

    '; $str = '
    ' . $str . '

    ' . $words->__get('continue') . '.

    '; echo new Display($str); die(); } return '

    ' . $words->__get('upload') . ' ' . $words->__get('files to this folder') . '

    '; } } ?>