Hi again guys please forgive my unknowing, i tried but simpply got errors.

I downloaded this upload script ( Click Here ), it works great except it's for single file uploads, not multi-file uploads

The website I'm working on requires the ability to upload multiple files at the same time, can anyone please help me convert this file to be able to support multi-file uploads.

(code cleaned so just the neccessary code is showing, for full code (styles etc) see the link above

This is the index.php file, config file sinply sets the directories and passwords and size limit.

<?
include("config.php");

function path_options()
{
 global $upload_dirs;
  $option = "";
  foreach ($upload_dirs as $path => $pinfo)
  {
    $option .= '<option value="'.$path.'">'.$pinfo["name"].'</option>';
  }
 return $option;
}

function check_vals()
{
 global $upload_dirs, $err;
    if (!ini_get("file_uploads")) { $err .= "HTTP file uploading is blocked in php configuration file (php.ini). Please, contact to server administrator."; return 0; }
    $pos = strpos(ini_get("disable_functions"), "move_uploaded_file");
    if ($pos !== false) { $err .= "PHP function move_uploaded_file is blocked in php configuration file (php.ini). Please, contact to server administrator."; return 0; }
  if (!isset($_POST["path"]) || (strlen($_POST["path"]) == 0)) { $err .= "Please fill out path"; return 0; }
  if (!isset($upload_dirs[$_POST["path"]])) { $err .= "Incorrect path"; return 0; }
  if (!isset($_POST["pwd"]) || (strlen($_POST["pwd"]) == 0)) { $err .= "Please fill out password"; return 0; }
  elseif ($_POST["pwd"] != $upload_dirs[$_POST["path"]]["password"]) { $err .= "The upload password is incorrect"; return 0; }
  if (!isset($_FILES["userfile"])) { $err .= "Empty file"; return 0; }
  elseif (!is_uploaded_file($_FILES['userfile']['tmp_name'])) { $err .= "Empty file"; return 0; }
 return 1;
}

$err = ""; $status = 0;
if (isset($_POST["upload"])) {
  if (check_vals()) {
    if (filesize($_FILES["userfile"]["tmp_name"]) > $max_file_size) $err .= "Maximum file size limit: $max_file_size bytes";
    else {
      if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $upload_dirs[$_POST["path"]]["dir"].$_FILES["userfile"]["name"])) {
                $status = 1;
            }
      else $err .= "There are some errors!";
    }
  }
}

if (!$status) {
  if (strlen($err) > 0) echo "<h4>$err</h4>";
}
else {
  echo "<h4>"".$_FILES["userfile"]["name"]."" was successfully uploaded.</h4>";
}
?>

<form enctype="multipart/form-data" action="index.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="<?=$max_file_size?>" />
<table class="main_table" align="center">
  <tr>
    <td colspan="2" class="head_line"> </td>
  </tr>
  <tr>
    <td>Folder:</td>
    <td><select name="path"><?=path_options()?></select></td>
  </tr>
  <tr>
    <td>Password:</td>
    <td><input type="password" name="pwd" style="width: 217px;" /></td>
  </tr>
  <tr>
    <td>Choose file:</td>
    <td><input type="file" name="userfile" style="width: 222px;" /></td>
  </tr>
  <tr>
    <td colspan="2" align="right"><input type="submit" name="upload" value="Upload" class="button" /></td>
  </tr>
</table>
</form>

Thanks in advance for your help

The website I'm working on requires the ability to upload multiple files at the same time, can anyone please help me convert this file to be able to support multi-file uploads.

Do you mean that you want multiple <input type="file"> ? You can add them using Javascript/jQuery on the click of a button. Another option is to use a tool like plUpload.

At line 67: <input type="file" name="userfile" style="width: 222px;" multiple />. After that you will have to find out how many files were updated: $number_files = sizeof($_POST['userfile']['name']);. After you've found out how many files were uploaded you can process them in a for() loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.