php+jq实现多图片上传

1.上传显示图片,实时提交文件

function BigFileUpload(showId,fileFormId,delurl,downloadurl){
    var fileName = new Array();
    var that = this;
    $(fileFormId).form({
        success:function(data){  //返回信息[['文件名称','完整路径'],['','']...]
//                $(showId+"  .shadow").css("display","none");
            data = eval('(' + data + ')');
            $.each(data,function(index,val){
                allpath.push(val[1]);
                console.log(allpath);
                if(index<10){
                    $(showId).append(cloneFileContent(val)); 
                }
                
            });
            console.log(allpath);
            
        }
    });
 
    function cloneFileContent(flName){

        var  temp = $("<div class='colondediv' style='width: 60px;height: 50px;float: left'><img  src='' style='width: 60px;height: 50px;margin-top: 12px;' class='col_servicePictureImgPreview'>" +
            "<div style='position: relative;width: 16px;height: 16px;float: right;margin-top: -60px' class='close'>"
            +"<img  src='../images/close.png' style='width: 15px;height: 15px;' ></div>"+
            "</div>").clone();
        temp.find(".col_servicePictureImgPreview").attr("src", '../images/'+flName[1]);//find() 方法获得当前元素集合中每个元素的后代,通过选择器、jQuery 对象或元素来筛选。
        temp.find(".close").click(function(){
            $.post(delurl,{'fileGuid':flName[1]},function(data){
                if(data.state=='success'){
                    console.log(data);
                    allpath=allpath.filter(function (x) {
                        return x!=flName[1];
                    })
                    console.log(allpath);
                    temp.remove();
                }

            },"json")
        });

        return temp;

    };


    this.operate = function(input){
        
       
        $(fileFormId).form("submit");

    };
    this.getFilenames = function(){
        console.log(fileName);
        return fileName;
    }
}
lessionFileUpload = new BigFileUpload("#col_servicePictureImgDivPreview","#lessionfileForm","{{ path('lessionFileDel') }}","{{ asset('fileUrl') }}");
<input  id="col_servicePictureImgDivAdd"  type="button" readonly="readonly" value="添加图片"  οnclick="$('#lessionfileForm #fileUploadInput').click()" style="width: 173px" />
<div  id="col_servicePictureImgDivPreview" style='display:inline-block'>
   
</div>
<form style="display: none" class="easyui-form" method="post" enctype="multipart/form-data" action="{{ path('lessionFileUpload') }}" id="lessionfileForm">
    <input id="fileUploadInput" type="file" multiple name="trainFile[]" οnchange="lessionFileUpload.operate(this)"/>
</form>

2.修改信息是实现显示图片每张图片左上角有关闭按钮

if(addressaddress!=''&& addressaddress !=null){

        /*本地预览展示*/
console.log(addressaddress);
            $.each(addressaddress.split(','),function(index,val){
                nowaddress.push(val);
                if(index<10){
                    $("#col_servicePictureImgDivPreview").append(localShowImage(val));

                }
              
            });

        function localShowImage(address) {



            var fulContent=$("<div class='colondediv' style='width: 60px;height: 50px;float: left'><img  src='' style='width: 60px;height: 50px;margin-top: 12px;' class='col_servicePictureImgPreview'>" +
                "<div style='position: relative;width: 16px;height: 16px;float: right;margin-top: -60px' class='close'>"
                +"<img  src='../images/close.png' style='width: 15px;height: 15px;' ></div>"+
                "</div>").clone();
            fulContent.find(".col_servicePictureImgPreview").attr("src", '../images/'+address);
            fulContent.find(".close").click(function(){

                $.post('lessionFileDel',{'fileGuid':address},function(data){
                    if(data.state=='success'){
                        nowaddress=nowaddress.filter(function (x) {
                            return x!=address;
                        })
                    console.log(nowaddress);

                    $.post('updatejiyaoaddress',{'address':nowaddress.join(),'meetindid':meetingidf},function () {

                    },'json')
                    fulContent.remove();
                    }

                },"json")
            });
            return fulContent;
        }
    }

转载于:https://my.oschina.net/u/3161974/blog/904483

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值