Heim > php教程 > php手册 > Tp3.2 图片上传+水印+缩略图 多图和单图

Tp3.2 图片上传+水印+缩略图 多图和单图

WBOY
Freigeben: 2016-06-07 11:38:48
Original
1694 Leute haben es durchsucht

Tp3.2 图片上传+水印+缩略图 多图和单图
//图像上传<br>     function uploadify()<br>     {<br>         if (!empty($_FILES)) {<br>             //图片上传设置<br>             $config = array(   <br>                 'maxSize'    =>    3145728, <br>                 'savePath'   =>    '',  <br>                 'saveName'   =>    array('uniqid',''), <br>                 'exts'       =>    array('jpg', 'gif', 'png', 'jpeg'),  <br>                 'autoSub'    =>    true,   <br>                 'subName'    =>    array('date','Ymd'),<br> <br>             );<br>             <br>             $upload = new \Think\Upload($config);// 实例化上传类<br>             $images = $upload->upload();<br> <br>             //判断是否有图<br>             if($images){<br>                 $info='Uploads/'.$images['Filedata']['savepath'].$images['Filedata']['savename'];<br>                 $miinfo='Uploads/'.$images['Filedata']['savepath'].'mi_'.$images['Filedata']['savename']; <br> <br>                 $image = new \Think\Image(); <br>                 $image->open('./'.$info)->thumb(150, 150,\Think\Image::IMAGE_THUMB_CENTER)->save('./'.$miinfo);  <br>                 //添加图片水印                <br>                 $image->open('./'.$info)->water('./Data/logo.png',\Think\Image::IMAGE_WATER_NORTHWEST,50)->save('./'.$info);<br>                 //添加文字水印<br>                 //$image->open('./'.$info)->text('姜医生','./Data/1.ttf',20,'#000000',\Think\Image::IMAGE_WATER_SOUTHEAST)->save($info);<br>                 $data['yt']= $info; <br>                 $data['mi']= $miinfo;  <br>                 $this->ajaxReturn($data);     <br>                 <br>                 <br>                 <br>             }<br>             else{<br>                 $this->error($upload->getError());//获取失败信息<br>             }<br>         }<br>     }注意水印图片文件 和 字体文件 两个文件丢失会出错

前端代码<link> <br> <script></script><br> <script></script><br> 引用样式文件<br>  <form> <br>                     <div> <br>                         <div> <br>                             <div> <br>                                 <fieldset> <br>                                     <legend>图片列表</legend> <br>                                 <div> <br>                                     <div> <br>                                         <a>删除</a><br>                                         <p><br>                                             <img alt="Tp3.2 图片上传+水印+缩略图 多图和单图" ><br>                                             <input><br>                                         </p> <br>                                         <p>face.jpg</p> <br>                                     </div> <br>                                     <div> <br>                                         <a>删除</a><br>                                         <p><br>                                             <img alt="Tp3.2 图片上传+水印+缩略图 多图和单图" ><br>                                             <input><br>                                         </p> <br>                                         <p>face.jpg</p> <br>                                     </div> <br>                                 </div> <br>                                 <div></div> <br>                                 <input><br>                                 </fieldset> <br>                             </div> <br>                         </div> <br>                         <div> <br>                             <div> <br>                                 <img alt="Tp3.2 图片上传+水印+缩略图 多图和单图" ><br>                                 <input><br>                                 <p><input><br>                                     <a>取消上传</a><br>                                 </p> <br>                             </div> <br>                         </div> <br>                         <br>                     </div> <br>                     <div> <br>                         <input><br>                     </div> <br>                 </form> <br> <br> <script><br /> $(function() {<br /> $(&#039;#IFY-list&#039;).uploadify({<br /> &#039;swf&#039; : &#039;__Public__/js/uploadify/uploadify.swf?ver=123&#039;,//swf文件路径<br /> &#039;uploader&#039; : &#039;__URL__/uploadify&#039;,//服务器端脚本文件路径<br /> &#039;fileObjName&#039;: &#039;Filedata&#039;,//上传附件$_FILE标识<br /> &#039;fileSizeLimit&#039;: &#039;5MB&#039;,//上传附件大小,0不限制,5120B/512KB/2MB/1GB<br /> &#039;fileTypeDesc&#039;: &#039;支持的格式:*.jpg;*.jpge;*.gif;*.png&#039;,<br /> &#039;fileTypeExts&#039;: &#039;*.jpg;*.jpge;*.gif;*.png&#039;,//上传附件后缀限制,*.*不限制<br /> &#039;auto&#039;:true, //开启,自动上传<br /> &#039;multi&#039; : true, //开启,多选文件<br /> &#039;uploadLimit&#039; : 10, //允许上传文件个数<br /> <br /> &#039;buttonText&#039;:&#039;附件上传&#039;,<br /> &#039;width&#039;:&#039;128&#039;,<br /> &#039;height&#039;:&#039;43&#039;,<br /> <br /> &#039;queueID&#039;:&#039;IFY-list-queue&#039;,//上传队列容器<br /> &#039;queueSizeLimit&#039;:10,//上传队列长度<br /> &#039;removeCompleted&#039;: false ,//上传完成移除<br /> <br /> &#039;itemTemplate&#039;:&#039;<div id="${fileID}" class="uploadify-queue-item">\<br /> <a class="ify-cancel" href="javascript:$(\&#039;#${instanceID}\&#039;).uploadify(\&#039;cancel\&#039;, \&#039;${fileID}\&#039;)">删除\<br /> <p class="ify-data"></script>

\
                    

${fileName}

\
                ',

        'overrideEvents': ['onUploadSuccess'],//可以被用户自定义事件覆盖
        'preventCaching':true,//后缀加随机数,防止缓存
        'requeueErrors':true,//上传出现错误后,重新加入队列
        'successTimeout':30,//等待服务器响应时间,超过30秒认为上传完成

        //没有兼容的FLASH时触发
        'onFallback':function(){
            alert("您未安装FLASH控件,无法上传图片!请安装FLASH控件后再试。");
        },
        //上传文件成功后触发(每一个文件都触发一次)
        'onUploadSuccess': function (file, data, response) {
            var data=jQuery.parseJSON(data);
            var yt='__ROOT__/'+data.yt;
            var mi='__ROOT__/'+data.mi;
            var img='Tp3.2 图片上传+水印+缩略图  多图和单图';
            $('#' + file.id).find('.ify-data').html(img);
        }
    });



    $('#IFY-one').uploadify({
        'swf'      : '__Public__/js/uploadify/uploadify.swf?ver=123',//swf文件路径
        'uploader' : '__URL__/uploadify',//服务器端脚本文件路径
        'fileObjName': 'Filedata',//上传附件$_FILE标识
        'fileSizeLimit': '5MB',//上传附件大小,0不限制,5120B/512KB/2MB/1GB
        'fileTypeDesc': '支持的格式:*.jpg;*.jpge;*.gif;*.png',
        'fileTypeExts': '*.jpg;*.jpge;*.gif;*.png',//上传附件后缀限制,*.*不限制
        'auto':true, //开启,自动上传
        'multi'    : true, //开启,多选文件
        'uploadLimit' : 10, //允许上传文件个数
        'buttonText':'附件上传',
        'width':'128',
        'height':'43',
        'queueID':'IFY-one-queue',//上传队列容器
        'queueSizeLimit':10,//上传队列长度
        'removeCompleted': true ,//上传完成移除
        'itemTemplate':'',
        'debug'    : false,//开启调试模式
        'overrideEvents': ['onUploadSuccess'],//可以被用户自定义事件覆盖
        'preventCaching':true,//后缀加随机数,防止缓存
        'requeueErrors':true,//上传出现错误后,重新加入队列
        'successTimeout':30,//等待服务器响应时间,超过30秒认为上传完成
        //没有兼容的FLASH时触发
        'onFallback':function(){
            alert("您未安装FLASH控件,无法上传图片!请安装FLASH控件后再试。");
        },
        //上传文件成功后触发(每一个文件都触发一次)
        'onUploadSuccess': function (file, data, response) {
            var data='__ROOT__/'+data;
            $('.music').find('audio').attr('src',data);
            $('.music').find('input').val(data);
        }
    });
    $('#IFY-one-cancel').click(function(){
        $('.ify-one-box').find('audio').attr('src',data);
        $('.ify-one-box').find('input').val('');
    });
});

附件 uploadify.zip ( 109.98 KB 下载:294 次 )

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

Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage