jquery.filer删除已上传的文件

时间:2016-02-06 01:10:04

标签: php jquery file-upload upload

我遇到了jquery.filer的问题!

#timeline{
height: 700px;
width: 100%;
background: #ff6952;
}

#timeline ul li{
color: white;
z-index: 100;
}

这是我对filer的“配置”。

    $(document).ready(function() {
        $('#filer_input').filer({
          showThumbs: true,
          templates: {
            box: '<ul class="jFiler-items-list jFiler-items-grid"></ul>',
            item: '<li class="jFiler-item">\
                        <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"></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">\
                            <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><span class="jFiler-item-others">{{fi-size2}}</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>',
            itemAppendToEnd: false,
            removeConfirmation: true,
            _selectors: {
            list: '.jFiler-items-list',
            item: '.jFiler-item',
            remove: '.jFiler-item-trash-action'
            }
            },
         addMore: true,
         limit:8,
         maxSize:2,
         extensions: ['jpg','gif','png'],
         files: [
        <?php 
        $path=SITEBASE.'uploads/';

        $i = 1;

        foreach (unserialize($input['gallery']) as $key => $photo) : ?>
            {
            name: "photo<?=$i?>.jpg",
            size: <?=filesize(UPLOAD.$photo)?>,
            type: "image/jpg",
            file: "<?=$path.$photo?>"
            },

        <?php 
        $i++;

        endforeach; ?>    
        ]

          });       
        });

现在,在结果中,一切都很完美。 已上传的所有图片均显示在网站上。

我尝试上传新文件并添加到数据库。

<form name="photoform" method="post" action="" enctype="multipart/form-data">
<input type="file" name="files[]" id="filer_input" multiple="multiple">
<input type="submit" name="photoformuploadphoto" value="SEND" />
</form>

不幸的是, $ files = $ data ['data'] 只返回新上传的文件。 这意味着我已经上传的文件已被删除。

你知道怎么解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

你需要: 1.从数组中获取mysql的旧文件 2.将上传的文件添加到旧文件

$db_images = $db_row['images']; //only example

if($data['isComplete']){
    $files = $data['data'];

    foreach($files["files"] as $value){
        $db_images[] = $value;
    }
}

// now $db_images is ready
// write your query to update