MikeeeG
MikeeeG

Reputation: 341

multiple file upload not working correctly

I have a simple multiple file upload form and heres the PHP thats handling it. The problem im having is that it doesnt upload the files. What it does do is save a file named 'Array' with no file extension.

Here is my code thus far:

<form method="post" action="" enctype="multipart/form-data">
    <input name="note[]" type="file" multiple="multiple">
    <button type="submit" name="upload_notes">Upload</button></p>
</form>

and

$upload_notes = ( isset($_POST['upload_notes']) ? true : false );

if ($upload_notes) {

    $user_notes_folder = 'user-notes/'
    $valid_formats = array("doc", "pdf", "docx", "rtf");
    $max_file_size = 100000;
    $count = 0;

    foreach ($_FILES['note']['name'] as $f => $name) {     
        if ($_FILES['note']['error'][$f] == 4) {
            continue;
        }          
        if ($_FILES['note']['error'][$f] == 0) {               
            if ($_FILES['note']['size'][$f] > $max_file_size) {
                $message[] = "$name is too large!.";
                continue; 
            }
            elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
                $message[] = "$name is not a valid format";
                continue;
            }
            else{ 
                if(move_uploaded_file($_FILES["note"]["tmp_name"][$f], $user_notes_folder.$_FILES["note"]["name"]))
                $count++;
            }
        }
    }
}

Upvotes: 1

Views: 933

Answers (2)

Nassim
Nassim

Reputation: 250

That's because $_FILES["note"]["name"] is actually an Array. Change the following :

if(move_uploaded_file($_FILES["note"]["tmp_name"][$f], $user_notes_folder.$_FILES["note"]["name"]))

To :

if(move_uploaded_file($_FILES["note"]["tmp_name"][$f], $user_notes_folder.$_FILES["note"]["name"][$f]))

Upvotes: 0

Ben Fortune
Ben Fortune

Reputation: 32137

$user_notes_folder.$_FILES["note"]["name"] is an array.

Probably needs to be

$user_notes_folder.$_FILES["note"]["name"][$f]

Upvotes: 1

Related Questions