Reputation: 6763
i'm following this tutorial: http://net.tutsplus.com/tutorials/javascript-ajax/uploading-files-with-ajax/comment-page-1/#comments to learn how to upload multiple files via ajax.
This is my 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>
And this is my 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");
My code should be the same as the one in the tutorial. Thanks for helping.
Upvotes: 0
Views: 2369
Reputation: 14469
Change the 'name' attribute of your input from settingsUploadAvatar
to settingsUploadAvatar[]
.
Upvotes: 6