1

I upload images through ajax method in my yii2 app. I can choose multiple files to upload but I need to upload max 5 files. How can I do that? My view file:

<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 method which upload a files

<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>
Rosti
  • 161
  • 1
  • 15
  • 1
    Checkout this answer - http://stackoverflow.com/questions/10105411/how-to-limit-maximum-items-on-a-multiple-input-input-type-file-multiple#answer-10105631 – Suresh Feb 16 '17 at 07:05

0 Answers0