James Gedny James Gedny - 4 months ago 6
PHP Question

html/php not uploading files

I have looked all over stackoverflow and have not yet found a working answer.
The HTML form allows the user to upload multiple files using one single input, the values then travel to a php file (named upload.php) to be uploaded to their final resting place.... this doesn't happen.

My HTML form:

<form method="post" action="upload.php" enctype="multipart/form-data">
<input name="upload[]" type="file" multiple="multiple" />
<input type="submit" value="Upload Files" class="btn btn-default btn-sm"/>
</form>


My PHP file:

<?php
if(count($_FILES['upload']['name'])) {
foreach ($_FILES['upload']['name'] as $file) {
move_uploaded_file($_FILES["upload"]["tmp_name"], './uploads/'.$_FILES["upload"]["name"]);
}
}
?>

Answer

try this code

<form method="post" action="upload.php" enctype="multipart/form-data">
    <input name="upload[]" type="file" multiple="multiple" />
    <input type="submit" name="submit" value="Upload Files" class="btn btn-default btn-sm"/>
</form>

Your PHP file

<?php
if(isset($_POST["submit"]))
{
    if(count($_FILES['upload']['name'])) {  
        foreach ($_FILES['upload']['name'] as $key=>$file) {
            move_uploaded_file($_FILES['upload']['tmp_name'][$key], './uploads/'.$file);
        }  
    } 

}
?>
Comments