search
Homephp教程php手册tp完美整合多图片上传

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 src="/static/imghwm/default1.png" data-src="/Public/Uploads/&#039;+response+&#039;" class="lazy" name="&#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 src="/static/imghwm/default1.png" data-src="/Public/Uploads/&#039;+arr[i]+&#039;" class="lazy" name="&#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元

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.