Jump to content

[SOLVED] Multi FIle Upload Help


herghost

Recommended Posts

Hi all,

 

I have this form:

 

<?php
$userid = $_SESSION['SESS_USERID'];
if(isset($_POST['submit'])){
      $numfilesuploaded = $_POST['numuploads'];
      $count = 1;

          while ($count <= $numfilesuploaded)
          {
                  $conname = "new_file".$count;

                  $filetype = $_FILES[$conname]['type'];
                 
                  $filename = $_FILES[$conname]['name'];
                  if ($filename != '')
                  {
                    if ($filetype = "application/msword")
                    {
                        $maxfilesize = $_POST['maxsize'];
                        $filesize = $_FILES[$conname]['size'];
                        if($filesize <= $maxfilesize )
                        {
                              $randomdigit = rand(0000,9999);
                             
                              $newfilename = $filename;
                              $source = $_FILES[$conname]['tmp_name'];
                              $target = "users/$userid/".$newfilename;
                              move_uploaded_file($source, $target);
                              echo $count." File uploaded | ";
                      
                        
                        }
                        else
                        {
                            echo $count." File is too big! 10MB limit! |";
                        
                        }
                    }
                    else
                    {
                        echo " The file is not a supported type |";
                    }
                  }
          $count = $count + 1;
          }
      
      }
?>
<html>
<?php
    $numuploads = 5;
    $count = 1;
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
<?php
      while ($count <= $numuploads)
      {

?>
      <input name="new_file<?php echo $count; ?>" id="new_file<?php echo $count; ?>" size="30" type="file" class="fileUpload" />
      <?php
            $count = $count + 1;
      }
?>
      <input type = "hidden" name="maxsize" value = "10240000">
       <input type = "hidden" name="numuploads" value = "<?php echo $numuploads; ?>">
      <br>
      <button name="submit" type="submit" class="submitButton">Upload Files</button>

</form>

 

Which is meant to upload multiple files to a directory, it uploads 1 file fine, but as soon as I put more than one file in, it redirects back to the upload page with no message and does not upload any files.

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/154742-solved-multi-file-upload-help/
Share on other sites

You are probably exceeding the post_max_size setting and the $_POST array is empty, so $_POST['submit'] does not exist, so your code does not even think the form was submitted -

 

  post_max_size  integer

    Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize. ... If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty.

 

The way to detect this is to either place a GET parameter on the end of the URL that you can test to know that there should be an upload (something like ?action=upload) or you can test if $_SERVER['REQUEST_METHOD' ] == "POST" and then test for an empty $_POST array or an empty $_FILES array.

 

After you get past that error, your code also needs to test the ['error'] element of the uploaded file information before attempting to use any of the ['type'], ['size'], ['name'], or ['tmp_name'] information - http://www.php.net/manual/en/features.file-upload.errors.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.