javascript - How to delete an image in Krajee Boostrap FileInput? - Stack Overflow

Currently using this plugin for uploading pictures on my website and I am struggling to find a way to t

Currently using this plugin for uploading pictures on my website and I am struggling to find a way to trigger an event to call my php file when user hit the delete button after they uploaded an image. (How does the delete function work? )

(my upload is working perfectly! Just cannot get the delete part going)

html:

 <input id="input-upload" name="input-upload[]" type="file" multiple="true">

JS code:

$("#input-upload").fileinput({
        uploadUrl: 'uploadImg.php',
        deleteUrl: 'deleteImg.php',
        showCaption: false,
        dropZoneEnabled: false,
        maxFileSize: 7000,
        maxFileCount: 5,
        uploadAsync: false,
        allowedFileExtensions : ['jpg', 'png','gif'],


        previewFileType: "image",
    browseClass: "btn btn-success",
    browseLabel: "Pick Image",
    browseIcon: '<i class="glyphicon glyphicon-picture"></i>',
    removeClass: "btn btn-danger",
    removeLabel: "Delete",
    removeIcon: '<i class="glyphicon glyphicon-trash"></i>',
    uploadClass: "btn btn-info",
    uploadLabel: "Upload",
    uploadIcon: '<i class="glyphicon glyphicon-upload"></i>',
        initialPreviewShowDelete:true,

    });

I also tried various event, like filepredelete and filedeleted functions, but those events were never called when user hit the delete button. Only the fileclear event works, but this is pointless because I will always get an empty list back and it is not useful because I cannot delete those uploaded files on my server.

I want to find a way to get the current list or find out what image the user deleted so that I can remove it in the server. (getting my input-upload array back prior to deletion and after)

Could anyone please help me out here? Thanks in advance!

Currently using this plugin for uploading pictures on my website and I am struggling to find a way to trigger an event to call my php file when user hit the delete button after they uploaded an image. (How does the delete function work? )

(my upload is working perfectly! Just cannot get the delete part going)

html:

 <input id="input-upload" name="input-upload[]" type="file" multiple="true">

JS code:

$("#input-upload").fileinput({
        uploadUrl: 'uploadImg.php',
        deleteUrl: 'deleteImg.php',
        showCaption: false,
        dropZoneEnabled: false,
        maxFileSize: 7000,
        maxFileCount: 5,
        uploadAsync: false,
        allowedFileExtensions : ['jpg', 'png','gif'],


        previewFileType: "image",
    browseClass: "btn btn-success",
    browseLabel: "Pick Image",
    browseIcon: '<i class="glyphicon glyphicon-picture"></i>',
    removeClass: "btn btn-danger",
    removeLabel: "Delete",
    removeIcon: '<i class="glyphicon glyphicon-trash"></i>',
    uploadClass: "btn btn-info",
    uploadLabel: "Upload",
    uploadIcon: '<i class="glyphicon glyphicon-upload"></i>',
        initialPreviewShowDelete:true,

    });

I also tried various event, like filepredelete and filedeleted functions, but those events were never called when user hit the delete button. Only the fileclear event works, but this is pointless because I will always get an empty list back and it is not useful because I cannot delete those uploaded files on my server.

I want to find a way to get the current list or find out what image the user deleted so that I can remove it in the server. (getting my input-upload array back prior to deletion and after)

Could anyone please help me out here? Thanks in advance!

Share Improve this question edited May 23, 2015 at 14:48 Ryan Fung asked May 23, 2015 at 7:03 Ryan FungRyan Fung 2,21711 gold badges41 silver badges62 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

Add initialPreview

initialPreview for your uploaded images:

initialPreview: {
    `img src='/images/desert.jpg' class='file-preview-image' alt='Desert' title='Desert'>`",
    `<img src='/images/jellyfish.jpg' class='file-preview-image' alt='Jelly Fish' title='Jelly Fish'>`",
},

Then add Config to this Preview:

initialPreviewConfig:

{
                {
                    caption: 'desert.jpg',
                    width: '120px',
                    url: '/localhost/public/delete', 
                    key: 100,
                    extra: {id: 100}   ***// id of your image***
                   }};

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745328601a4622772.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信