Abhijit Das
Abhijit Das

Reputation: 105

multiple file uploading code error

<?php
if(isset($_FILES['files']['name']))
{
    foreach($_FILES['files']['name'] as $key)
    {
    echo $file_name = $_FILES['files']['name'][$key];
    }
}
?>


<form action="test.php" method="POST" enctype="multipart/form-data">
<input type="file" name="files[]" multiple />
<input type="submit" value="submit">
</form>

I want to echo the file names. But i got error

Notice: Undefined index: 1_t.jpg in D:\xampp1\htdocs\imageupload\test.php on line 6

Notice: Undefined index: 2_t.jpg in D:\xampp1\htdocs\imageupload\test.php on line 6

Notice: Undefined index: 007.jpg in D:\xampp1\htdocs\imageupload\test.php on line 6

Upvotes: 0

Views: 33

Answers (1)

zepner
zepner

Reputation: 26

This should work

<?php
$filenames = array();
if(isset($_FILES['files']['name'])) {
    foreach($_FILES['files']['name'] as $name) {
      $filenames[] = $name;
    }
}
print implode('<br/>', $filenames);
?>


<form method="POST" enctype="multipart/form-data">
<input type="file" name="files[]" multiple />
<input type="submit" value="submit">
</form>

Upvotes: 1

Related Questions