1

I try to be more specific, the first try was not that.

I'd like to upload 3 images with php. I need all file data (name, size, tmp_name, type) and also the name of the current input field after form submit.

<input type="file" name="thisisaname"...>
<input type="file" name="thisisanothername"...>
<input type="file" name="thethirdname"...>

I'd need the ImageInputname in my foreach:

foreach($_FILES as $file)
{
$ImageName      = $file['name'];
$ImageSize      = $file['size'];
$TempSrc        = $file['tmp_name'];
$ImageType      = $file['type'];
$ImageInputName = ???
...
}

What is the easiest way to get the input name?

1

1 Answer 1

0

You can use this code to upload multiple file upload in php.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
  <p><input type="file" name="file_array[]"></p>
  <p><input type="file" name="file_array[]"></p>
  <p><input type="file" name="file_array[]"></p>
  <input type="submit" value="Upload all files">
</form>
</body>
</html>

<?php
        if(isset($_FILES['file_array'])){
            $name_array = $_FILES['file_array']['name'];
            $tmp_name_array = $_FILES['file_array']['tmp_name'];
            $type_array = $_FILES['file_array']['type'];
            $size_array = $_FILES['file_array']['size'];
            $error_array = $_FILES['file_array']['error'];

            for($i = 0; $i < count($tmp_name_array); $i++){
                if(move_uploaded_file($tmp_name_array[$i], "test_uploads/".$name_array[$i])){
                    echo $name_array[$i]." upload is complete<br>";
                } else {
                    echo "move_uploaded_file function failed for ".$name_array[$i]."<br>";
                }
            }

        }
?>
Sign up to request clarification or add additional context in comments.

1 Comment

can you explain what's going on here?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.