<form action = "uploadFile.php" method= "POST"  enctype = "multipart/form-data">
      <input type = "file" name = "file[]"><br><br>
      <input type = "file" name = "file[]"><br><br>
      <input type = "submit" value = "Submit">
</form>


Is it possible to upload more than one file at the same time with just a click on the submit button?
I am having this problem of figuring out what to do as to uploading multiple files at the same time? Any idea please?

Dani AI

Generated

Good thread — building on what started and pointed toward, here’s a compact, practical plan for accepting many files and deciding whether to store them in the database.

Decide the storage model first. For many or large uploads, store files on disk or an object store (S3) and keep metadata (original name, mime, size, path, owner, timestamp) in the DB. If you must store binaries in the DB, use an appropriate BLOB column (MEDIUMBLOB/LONGBLOB for larger content) and keep uploads small to avoid DB bloat. Use a dedicated uploads table and wrap inserts in a transaction so partial failures are easy to detect and roll back.

A minimal server-side example using PDO to insert file data and metadata (adapt to your field names and validation):

// $pdo = new PDO(...);
$stmt = $pdo->prepare(
  "INSERT INTO uploads (filename, mime, size, data) VALUES (:name, :mime, :size, :data)"
);

foreach ($_FILES['files']['error'] as $i => $err) {
    if ($err !== UPLOAD_ERR_OK) continue;
    $tmp  = $_FILES['files']['tmp_name'][$i];
    $name = $_FILES['files']['name'][$i];
    $mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $tmp);
    $data = file_get_contents($tmp);
    $stmt->execute([':name'=>$name, ':mime'=>$mime, ':size'=>strlen($data), ':data'=>$data]);
}

Quick troubleshooting and safety notes: validate MIME and size, sanitize or replace filenames, check php.ini limits (upload_max_filesize, post_max_size, memory_limit) and web‑server body size settings, inspect upload error codes, and prefer move_uploaded_file for filesystem storage. See the PHP manual for file uploads and safe move handling: PHP file uploads and move_uploaded_file.

Recommended Answers

All 2 Replies

The code you have there will upload 2 files. The resultng array %_FILES['files'] that is posted will contain them both.
What exactly are you having trouble with?
Something to remember is that PHP has a config setting MAX_FILE_UPLOADS (since PHP 5.2 I think) that specifies the maximum number of files can be uploaded in one go.

I initially had the issue, or problem of choosing how to go about uploading the respective files! I first thought that maybe I should upload them individually, but I have already resolved how to go about it. Uploading all the files at a go will be better and then capturing the error for any failed file was the final means I employed.

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.