I'm attempting to list all the filenames of images uploaded via a form to then be sent via email.
fileupload.html:
<form method="post" action="upload.php" enctype="multipart/form-data" id="upload" >
<input type="file" name="filesupl[]" multiple id="files" />
<input type="submit" name="UploadBtn" value="Upload" class="formtext" id="UploadBtn">
</form>
upload.php:
$art_file = $_FILES['filesupl'];
$filecounter = 1;
$count = 0;
foreach ( $art_file as $i => $art_inner ){
echo $filecounter . ") " . $art_file[$i]['name'] . "<br />"; $filecounter++;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' and isset($_FILES['filesupl']))
{
$extension = pathinfo($_FILES['filesupl']['name'], PATHINFO_EXTENSION);
// Upload files
// loop all files
foreach ( $_FILES['filesupl']['name'] as $i => $name )
{
// if file not uploaded then skip it
if ( !is_uploaded_file($_FILES['filesupl']['tmp_name'][$i]) )
continue;
// skip large files
if ( $_FILES['filesupl']['size'][$i] >= $max_size )
continue;
// skip unprotected files
if( !in_array(pathinfo($name, PATHINFO_EXTENSION), $extensions) )
continue;
// now we can move uploaded files
if( move_uploaded_file($_FILES["filesupl"]["tmp_name"][$i], $dir . $name) )
$count++;
}
}
echo json_encode(array('count' => $count));
I've attempted numerous ways to access the 'name' of the files uploaded (the code above was one of those attempts), to no avail.