多文件上传无法正常工作

时间:2013-09-20 10:13:20

标签: php file-upload

我有一个简单的多文件上传表单,而且是处理它的PHP。我遇到的问题是它没有上传文件。它所做的是保存一个名为'Array'的文件,没有文件扩展名。

到目前为止,这是我的代码:

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

$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 个答案:

答案 0 :(得分:1)

$user_notes_folder.$_FILES["note"]["name"]是一个数组。

可能需要

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

答案 1 :(得分:0)

那是因为$ _FILES [“note”] [“name”]实际上是一个数组。更改以下内容:

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

致:

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