PHP多文件上传:为foreach()提供的参数无效

时间:2012-02-23 14:06:12

标签: php file-upload

我正在关注本教程:http://net.tutsplus.com/tutorials/javascript-ajax/uploading-files-with-ajax/comment-page-1/#comments以了解如何通过ajax上传多个文件。

这是我的HTML:

<form class="form-horizontal" id="settingsChangeAvatar" method="post" enctype="multipart/form-data" action="<?php echo $AJAX."/ajaxUpload.php"?>">
    <input class="input-xlarge input-file" id="settingsUploadAvatar" name="settingsUploadAvatar" type="file" multiple />
    <button class="btn" id="uploadAvatarButton" type="submit">Upload</button>
</form>

这是我的ajaxUpload.php:

foreach($_FILES["settingsUploadAvatar"]["error"] as $key => $error){
    if($error == UPLOAD_ERR_OK) {
        $name = $_FILES["settingsUploadAvatar"]["name"][$key];
        move_uploaded_file($_FILES["settingsUploadAvatar"]["tmp_name"][$key], $_SERVER["DOCUMENT_ROOT"]."/webname/".$_FILES["settingsUploadAvatar"]["name"][$key]);
    }
}

echo("File uploaded");

我的代码应与教程中的代码相同。 谢谢你的帮助。

1 个答案:

答案 0 :(得分:6)

将输入的“名称”属性从settingsUploadAvatar更改为settingsUploadAvatar[]