首頁 >php教程 >php手册 >tp完美整合多图片上传

tp完美整合多图片上传

WBOY
WBOY原創
2016-06-07 11:44:241826瀏覽

tp完美整合多图片上传,网上找了很多控件均不能达到自己的要求,最后自己参考官方的例子结合自己对tp的不多认识,整合出来了适合自己用的,最近忙着项目,改天整理好了,单独分离出来上传分享,尽请期待哦; (暂时先把没改过的实例包发上来吧!有需要的朋友可以拿去参考)
更多技术文章请移步
http://www.dahuzhi.com
tp完美整合多图片上传tp完美整合多图片上传tp完美整合多图片上传tp完美整合多图片上传

以下是部分代码:<br> <br> <!--多文件上传--><br> <link> <br> <link> <br> <script></script><br> <script></script><br> <script></script><br> <br> <script><br /> $(document).ready(function() {<br /> $("#uploadify").uploadify({<br /> &#039;uploader&#039; : &#039;/Public/duo_uploads/scripts/uploadify.swf&#039;, //上传按钮<br /> &#039;script&#039; : &#039;/index.php/article/upload&#039;, //ajax请求文件<br /> &#039;cancelImg&#039; : &#039;/Public/images/cancel.png&#039;, //关闭按钮图片地址<br /> &#039;folder&#039; : "../uploads/<{$time}>/", //时间<br /> &#039;queueID&#039; : &#039;fileQueue&#039;,<br /> &#039;fileExt&#039; : &#039;*.jpg;*.gif;*.bmp;&#039;, //允许文件上传类型,和fileDesc一起使用.<br /> &#039;fileDesc&#039; : &#039;*.jpg;*.gif;*.bmp;&#039;, //将不允许文件类型,不在浏览对话框的出现.<br /> &#039;auto&#039; : false,<br /> &#039;multi&#039; : true, //是否支持多文件上传<br /> &#039;onComplete&#039;:function(event,queueId,fileObj,response,data){<br /> $(&#039;#info&#039;).html($(&#039;#info&#039;).html() + &#039;<div class="img_box" ><img name="&#039;+ response +&#039;" src="/Public/Uploads/&#039;+response+&#039;" style="max-width:90%" style="max-width:90%" alt="tp完美整合多图片上传" > <p onclick=del_img(this); >删除</script>

');//在页面上显示文件相对路径
            
        }
    });
});

//删除文件
function  del_img(whichSong)
{
    //盒子对象
    var info = document.getElementById('info');
    //当前图片对象
    var zi = whichSong.parentElement;
    //图片名称
    var path = zi.firstChild.name
    //产生对象
    var ajax=new XMLHttpRequest;
    //生成事件处理器
    ajax.onreadystatechange=function(){
        if (ajax.readyState==4) {             //判断请求状态为4完成的时候
            if (ajax.status==200) {         //判断服务器的http状态码等于200
                //alert(ajax.responseText); //弹出服务器的响应
                if(ajax.responseText)
                {
                    //删除当前
                    info.removeChild(zi);
                }
            }
        }
    }
    //打开链接
    ajax.open('post','/index.php/article/img');
    //设置http传输
    ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    //发送
    ajax.send('action=del_img&path=' + path);
}





<script><br /> $(document).ready(function() {<br /> <br /> //所有的图片<br /> var imgs = $(&#039;#imgs&#039;).val();<br /> var str = &#039;&#039;;<br /> //分割图片<br /> arr = imgs.split(&#039;,&#039;);<br /> <br /> //组合每个图片html<br /> for(var i = 0; i < arr.length; i++)<br /> {<br /> if(arr[i])<br /> {<br /> str += &#039;<div class="img_box" ><img name="&#039;+ arr[i] +&#039;" src="/Public/Uploads/&#039;+arr[i]+&#039;" style="max-width:90%" style="max-width:90%" alt="tp完美整合多图片上传" > <p onclick=del_img(this); >删除<input type="hidden" name="imgs[]" value="&#039;+ arr[i] +&#039;">&#039;;<br /> }<br /> }<br /> <br /> //所有图片html添加到已上传的图片盒子里<br /> $(&#039;#info&#039;).html(str);<br /> });<br /> </script>



            
    

        
        
        

            内容列表
            内容管理/
            图片发布
        

    

    
    

        

            图片编辑图片发布
        

        

            
            
            

                

                editadd"/>
                
                    "/>
                    "/>
                    "/>
                
                
                
                

                    
    
                        
                        
                            
                            
                            
                        
                        
                            
                            
                        
                    
相片:
                                

                                    

                                    

                                        
                                        上传
                                        取消上传
                                        

提示:只能上传
(jpg,gif,bmp)
格式图片


                                    


                                    

                                

                            
 
                                
                            

                

                

            

        

    




//多文件上传<br>     function upload() <br>     {<br>         import("ORG.Net.Image3");<br>         if (!empty($_FILES)) <br>         {<br>             //获取文件名<br>             $tempFile         = $_FILES['Filedata']['tmp_name'];<br>             //保存路径<br>             $targetPath     = APP_PATH . 'Public/Uploads/';<br>             //新图片名<br>             $new_file_name     = new_name( $_FILES['Filedata']['name']);<br>             //图片网站路径<br>             $targetFile     = $targetPath . $new_file_name;<br>             <br>             //判断是否文件夹存在<br>             if(!is_dir($targetPath))<br>                 mkdir($targetPath, 0777, true);<br>         <br>             //防止中文文件名乱码<br>             move_uploaded_file($tempFile,iconv('utf-8','gbk', $targetFile));<br>             <br>             //水印<br>             $water = 'water.gif';<br>             $img   = new Image3();<br>             $img->param($targetFile)->water($targetFile,$water,9);<br>             //ajax返回图片名称<br>             echo get_relative_path($new_file_name);<br>         }<br>     }<br>     <br>     //图片模块<br>     public function img()<br>     {<br>         $c = D('class');<br>         $a = D('article');<br>         if($_POST['action'] == 'add')<br>         {<br>             //判断是否有上传多文件<br>             if($_POST['imgs'])<br>             {<br>                 $_POST['img'] = '';<br>                 foreach ($_POST['imgs'] as $v)<br>                 {<br>                     $_POST['img'] .= $v . ',';<br>                 }<br>             }<br>     <br>             //加载上传类<br>             $file = static::get_file(2097152);<br>             //判断是否上传文件<br>             $_POST['simg']    = ($file) ? $file : '' ;<br>             $_POST['addtime'] = exec_time();<br>             //dump($_POST);die();<br>             //过滤数据并添加<br>             $a->create();<br>             if($a->add())<br>                 static::success('添加成功', 3000, 1, 0);<br>         }<br> <br>         //获取所有分类信息<br>         $data = $c->order('nos asc')->select();<br>         //格式化无线分类<br>         $data = static::get_class($data);<br>         $this->assign('data', $data);<br>         //时间输出<br>         $this->assign('time', date('Y-m-d', time()));<br>         $this->display();<br>     }

附件 uploadify_v1.0.rar ( 62.44 KB 下载:882 次 )

AD:真正免费,域名+虚机+企业邮箱=0元

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn