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

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

WBOY
发布: 2016-06-07 11:38:48
原创
1694 人浏览过

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元

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板