lundi 30 juillet 2018

why image uploader is not working in laravel 5.6

I am working with laravel 5.6. in my application I have image uploader with preview using javascripts. this is My image upload preview,

<div class="form-group row">
                <label for="image" class="col-form-label col-md-3">Image</label>
                <div class="col-md-5">
                    <img id="preview"
                          src=""
                         height="200px" width="200px"/>
                    <input class="form-control" style="display:none" name="image" type="file" id="image">
                    <br/>
                    <a href="javascript:changeProfile();">Add Image</a> |
                    <a style="color: red" href="javascript:removeImage()">Remove</a>
                    <input type="hidden" style="display: none" value="0" name="remove" id="remove">
                </div>

and my javascript

<script>
        function changeProfile() {
            $('#image').click();
        }
        $('#image').change(function () {
            var imgPath = $(this)[0].value;
            var ext = imgPath.substring(imgPath.lastIndexOf('.') + 1).toLowerCase();
            if (ext == "gif" || ext == "png" || ext == "jpg" || ext == "jpeg")
                readURL(this);
            else
                alert("Please select image file (jpg, jpeg, png).")
        });
        function readURL(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();
                reader.readAsDataURL(input.files[0]);
                reader.onload = function (e) {
                    $('#preview').attr('src', e.target.result);
                    $('#remove').val(0);
                }
            }
        }
        function removeImage() {
            $('#preview').attr('src', '');
            $('#remove').val(1);
        }
    </script>

but when I click Add I image button images not selecting, Then how can fix this problem?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire