我在yii2应用中通过ajax方法上传图片。我可以选择上传多个文件,但我需要上传最多5个文件。我怎样才能做到这一点? 我的观看文件:
<div class="row">
<div class="col-lg-6">
<p class="add_photo"><img class="describe_images" src="photo.png"></img>Добавить фото(до 5 штук)</p>
<form enctype="multipart/form-data"
"method"="post" "id"="my-form">
<input name="media[]" type="file" multiple id ="gallery-photo-add"/>
<input class="button" type="submit" alt="Upload" value="Upload" />
</form>
</div>
<div class="col-lg-6 pixels-line">
<div class="preview"></div>
</div>
</div>
上传文件的ajax方法
<script>
$('#my-form').submit( function(e) {
e.preventDefault();
var data = new FormData(this); // <-- 'this' is your form element
$.ajax({
url: 'site/index',
data: data,
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function(data){
alert(data);
}
});
});
</script>