1

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++;
            }
        }
    }
}

2 Answers 2

1

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

Probably needs to be

$user_notes_folder.$_FILES["note"]["name"][$f]
Sign up to request clarification or add additional context in comments.

Comments

0

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]))

Comments

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.