Q:

Multifile upload

Looking for the following solutions: 
Form html / php provide the ability to add multiple graphic files (up to 11 files, max 5MB).
When sending to a server script should do the following:

check if the file has a good extension (jpg, png);
re-name each file according to the formula < string up to 32 characters > _ < 000 to 010 >. < extension >;
add file names to the table (one file = one column, row);
compress to a maximum resolution of 1280x1024;
change the proportions of graphics on 4: 3 images while maintaining the same proportions;
lessen the size of the file and save to the server in the appropriate folder.

I'm interested in possibly easy to use solution.Thank you very much for your help.

A:

try it,
HTML Code
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Multiple File Ppload with PHP</title>
</head>
<body>
  <form action="" method="post" enctype="multipart/form-data">
    <input type="file" id="file" name="files[]" multiple="multiple" accept="image/*" />
  <input type="submit" value="Upload!" />
</form>
</body>
</html>

PHP CODE
<?php
$valid_formats = array("jpg", "png");
$max_file_size = 1280*1024; 
$path = "uploads/"; // Upload directory
$count = 0;

if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
    // Loop $_FILES to exeicute all files
    foreach ($_FILES['files']['name'] as $f => $name) {     
        if ($_FILES['files']['error'][$f] == 4) {
            continue; // Skip file if any error found
        }          
        if ($_FILES['files']['error'][$f] == 0) {              
            if ($_FILES['files']['size'][$f] > $max_file_size) {
                $message[] = "$name is too large!.";
                continue; // Skip large files
            }
            elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
                $message[] = "$name is not a valid format";
                continue; // Skip invalid file formats
            }
            else{ // No error found! Move uploaded files 
                if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name))
                $count++; // Number of successfully uploaded file
            }
        }
    }
}
?>

