jQuery.filer - 在wordpress中简单的HTML5文件上传器图像删除

时间:2016-09-27 09:55:02

标签: javascript php jquery wordpress html5

我在wordpress上使用jquery filer html5 uploader。我想在帖子编辑页面上删除图片。有人可以帮忙吗?我在ajax_remove_file.php中使用unlink()函数jquery filer html5 uploader,但这不起作用

jQuery(document).ready(function($) {
    //Example 2
    $("#filer_input2").filer({
                <?php 
                    global $redux_demo;
                    $uploadlimit = $redux_demo['image-limit'];
                    $limitnum = 'null';
                    if(!empty($uploadlimit)){
                        $limitnum = $redux_demo['image-limit'];
                    }
                ?>
            limit: <?php echo $limitnum; ?>,
            maxSize: null,
            extensions: ["jpg", "png", "gif"],
            changeInput: '<div class="jFiler-input-dragDrop"><div class="jFiler-input-inner"><div class="jFiler-input-text"><h4><?php _e('Drag & Drop IMAGE here','agrg') ?></h4> <span style="display:inline-block; margin: 15px 0">or</span></div><a class="jFiler-input-choose-btn">Browse IMAGE</a></div></div>',
            showThumbs: true,
            theme: "dragdropbox",
            templates: {
                    box: '<ul class="jFiler-items-list jFiler-items-grid"></ul>',
                    item: '<li class="jFiler-item col-lg-3 col-md-4 col-sm-4 col-xs-12">\
                                            <div class="jFiler-item-container">\
                                                    <div class="jFiler-item-inner">\
                                                            <div class="jFiler-item-thumb">\
                                                                    <div class="jFiler-item-status"></div>\
                                                                    <div class="jFiler-item-info">\
                                                                            <span class="jFiler-item-title"><b title="{{fi-name}}">{{fi-name | limitTo: 25}}</b></span>\
                                                                            <span class="jFiler-item-others">{{fi-size2}}</span>\
                                                                    </div>\
                                                                    {{fi-image}}\
                                                            </div>\
                                                            <div class="jFiler-item-assets jFiler-row">\
                                                                    <ul class="list-inline pull-left">\
                                                                            <li>{{fi-progressBar}}</li>\
                                                                    </ul>\
                                                                    <ul class="list-inline pull-right">\
                                                                            <li><a class="icon-jfi-trash jFiler-item-trash-action"></a></li>\
                                                                    </ul>\
                                                            </div>\
                                                    </div>\
                                            </div>\
                                    </li>', 
                    itemAppend: '<li class="jFiler-item col-lg-3 append col-md-4 col-sm-4 col-xs-12">\
                                <div class="jFiler-item-container">\
                                        <div class="jFiler-item-inner">\
                                                <div class="jFiler-item-thumb">\
                                                        <div class="jFiler-item-status"></div>\
                                                        <div class="jFiler-item-info">\
                                                                <span class="jFiler-item-title"><b title="{{fi-name}}">{{fi-name | limitTo: 25}}</b></span>\
                                                                <span class="jFiler-item-others">{{fi-size2}}</span>\
                                                        </div>\
                                                    {{fi-image}}\
                                                </div>\
                                                <div class="jFiler-item-assets jFiler-row">\
                                                        <ul class="list-inline pull-left">\
                                                                <li><span class="jFiler-item-others">{{fi-icon}}</span></li>\
                                                        </ul>\
                                                        <ul class="list-inline pull-right">\
                                                                <li><a class="icon-jfi-trash jFiler-item-trash-action"></a></li>\
                                                        </ul>\
                                                </div>\
                                        </div>\
                                </div>\
                                </li>',                     
                    progressBar: '<div class="bar"></div>',
                    itemAppendToEnd: false,
                    removeConfirmation: true,
                    _selectors: {
                            list: '.jFiler-items-list',
                            item: '.jFiler-item',
                            progressBar: '.bar',
                            remove: '.jFiler-item-trash-action'
                    }
            },
            dragDrop: {
                    dragEnter: null,
                    dragLeave: null,
                    drop: null,
            },
            uploadFile: {
                    url: "<?php wp_upload_dir(); ?>",
                    data: null,
                    type: 'POST',
                    enctype: 'multipart/form-data',
                    beforeSend: function(){},
                    success: function(data, el){
                            var parent = el.find(".jFiler-jProgressBar").parent();
                            el.find(".jFiler-jProgressBar").fadeOut("slow", function(){
                                    $("<div class=\"jFiler-item-others text-success\"><i class=\"icon-jfi-check-circle\"></i> Success</div>").hide().appendTo(parent).fadeIn("slow");
                            });
                    },
                    error: function(el){
                            var parent = el.find(".jFiler-jProgressBar").parent();
                            el.find(".jFiler-jProgressBar").fadeOut("slow", function(){
                                    $("<div class=\"jFiler-item-others text-error\"><i class=\"icon-jfi-minus-circle\"></i> Error</div>").hide().appendTo(parent).fadeIn("slow");
                            });
                    },
                    statusCode: null,
                    onProgress: null,
                    onComplete: null
            },
            files:[<?php require_once(TEMPLATEPATH . '/inc/BFI_Thumb.php'); ?>
                    <?php
                        $count = 0;
                        $params = array( 'width' => 110, 'height' => 70, 'crop' => true );
                        $attachments = get_children(array('post_parent' =>          $current_post,
                                        'post_status' => 'inherit',
                                        'post_type' => 'attachment',
                                        'post_mime_type' => 'image',
                                        'order' => 'ASC',
                                        'orderby' => 'menu_order ID'));

                        foreach($attachments as $att_id => $attachment) {
                                        $attachment_ID = $attachment->ID;
                                        $attachment_title = get_the_title($attachment_ID);
                                        $full_img_url = wp_get_attachment_url($attachment->ID);
                                        $size = getimagesize($full_img_url);
                                        $ext = strtolower(end(explode('.', $full_img_url)));
                    ?>
                        {
                            name: "<?php echo $attachment_title; ?>.<?php echo $ext; ?>",
                            type: "image/<?php echo $ext; ?>",
                            size: "<?php echo $size; ?>",
                            id  :"<?php echo $attachment_ID; ?>",
                            file: "<?php echo $full_img_url; ?>",
                            url: "<?php echo $full_img_url; ?>"
                        },
                    <?php
                    $count++;
                        }
                    ?>
                ],
            addMore: false,
            clipBoardPaste: true,
            excludeName: null,
            beforeRender: null,
            afterRender: null,
            beforeShow: null,
            beforeSelect: null,
            onSelect: function () {
            // Mark as featured
            $('a.mark-featured').click(function(event){

                event.preventDefault();

                var $this = $( this );
                var starIcon = $this.find( 'i');

                if ( starIcon.hasClass( 'fa-star-o' ) ) {   // if not already featured

                    $('.jFiler-item-assets .featured-img-id').remove();      // remove featured image id field from all the gallery thumbs
                    $('.jFiler-item-assets .mark-featured i').removeClass( 'fa-star').addClass( 'fa-star-o' );   // replace any full star with empty star

                    var $this = $( this );
                    var input = $this.siblings( '.gallery-image-id' );      //  get the gallery image id field in current gallery thumb
                    var featured_input = input.clone().removeClass( 'gallery-image-id' ).addClass( 'featured-img-id' ).attr( 'name', 'featured_image_id' );     // duplicate, remove class, add class and rename to full fill featured image id needs

                    $this.closest( '.jFiler-item-assets' ).append( featured_input );     // append the cloned ( featured image id ) input to current gallery thumb
                    starIcon.removeClass( 'fa-star-o' ).addClass( 'fa-star' );      // replace empty star with full star

                }

            }); // end of mark as featured click event

        },
            afterShow: null,
            onRemove: function(itemEl, file, id, listEl, boxEl, newInputEl, inputEl){
                    var file = file.url;
                    $.post('<?php echo get_template_directory_uri(); ?>/inc/ajax_remove_file.php', {file: file});
            },
            onEmpty: null,
            options: null,
            captions: {
                    button: "Choose Files",
                    feedback: "Choose files To Upload",
                    feedback2: "files were chosen",
                    drop: "Drop file here to Upload",
                    removeConfirmation: "Are you sure you want to remove this file?",
                    errors: {
                            filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                            filesType: "Only Images are allowed to be uploaded.",
                            filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                            filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
                    }
            }
    });

});

0 个答案:

没有答案