首页  >  文章  >  php教程  >  TP3.2:上传预览 缩略图 水印实例

TP3.2:上传预览 缩略图 水印实例

WBOY
WBOY原创
2016-06-07 11:41:441109浏览

uploadify上传预览 缩略图 水印实例
首先感谢各位大神网友的分享,我只是改改代码,让其更符合自己的业务逻辑
图片上传 缩略图 水印处理代码:    //文件上传<br>     Public function _upload( $thumb = false , $thumbWidth = '' , $thumbHeight = '') {<br>         $upload = new ThinkUpload();// 实例化上传类<br>         $upload->maxSize = 3145728 ;// 设置附件上传大小<br>         $upload->exts =  array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型<br>         $upload->savePath =  '/' . CONTROLLER_NAME .'/'; // 设置附件上传目录<br>         $info = $upload->upload();<br>         if(!$info) {<br>             return array('status' =>0, 'info'=> $upload->getError() );<br>         }else{<br>             if( $thumb ) {    //生成缩略图<br> <br>                 $image = new ThinkImage(); <br> <br>                 foreach($info as $file) {<br>                     $thumb_file = './Uploads/' . $file['savepath'] . $file['savename'];<br>                     $save_path = './Uploads/' .$file['savepath'] . 'mini_' . $file['savename'];<br>                     $image->open( $thumb_file )->text('德兴房产','./data/1.otf',30,'#A7AAA4',ThinkImage::IMAGE_WATER_SOUTHWEST)->save( $thumb_file );<br>                     $image->open( $thumb_file )->text('德兴房产','./data/1.otf',24,'#A7AAA4',ThinkImage::IMAGE_WATER_SOUTHWEST)->thumb( $thumbWidth, $thumbHeight )->save( $save_path );<br>                     return array(<br>                         'status' => 1, <br>                         'savepath' => $file['savepath'],<br>                         'savename' => $file['savename'],<br>                         'pic_path' => $file['savepath'] . $file['savename'],<br>                         'mini_pic' => $file['savepath'] . 'mini_' .$file['savename']<br>                     );   <br>                 }<br>             }else{<br>                 foreach($info as $file) {<br>                     return array(<br>                         'status' => 1, <br>                         'savepath' => $file['savepath'],<br>                         'savename' => $file['savename'],<br>                         'pic_path' => $file['savepath'].$file['savename']<br>                     );   <br>                 }<br>             }<br>         }<br>     }前端主要代码(参考http://www.thinkphp.cn/code/151.html):                        <div class="tab-pane" id="tab3"><br>                             <div class="row"><br>                                 <div class="col-md-12"><br>                                     <div class="tab-pane"><br>                                         <div class="form-group"><br>                                             <input type="file" id="upload" class="form-control input-medium" /><br>                                         </div><br>                                         <div style="width:100%; float:left;padding:10px 20px 20px; background-color:#ccc"><br>                                             <p><br>                                                 <ul class="imagelist" id="image_result"></ul><br>                                             </p><br>                                         </div><br>                                     </div><br>                                 </div><br>                             </div><br>                         </div> <!-- END #TAB3 --><br> <br>                         <div class="margin-top-10"><br>                             <button type="submit" class="btn green ajax-post">确 认</button><br>                             <a href="javascript:" onclick="javascript:history.back(-1);return false;" class="btn default">返 回</a><br>                         </div><br>                     </div> <br>                 </div><br>             </form><br>         </div><br>     </div><br> </块><br> <br>     <link href="__PUBLIC__/assets/plugins/uploadify/uploadify.css" rel="stylesheet" type="text/css"> <br>     <link href="__PUBLIC__/assets/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css"> <br>     <script></script><br>     <script></script><br>     <br>     $(函数(){<br>         var sid = “{:session_id()}”;<br>         $('#upload').uploadify({<br>             'swf':'__PUBLIC__/assets/plugins/uploadify/uploadify.swf',<br>             'buttonText': '选择图片',<br>             'formData': { 'session_id':sid},<br>             '上传者': "{:U('uploadPic')}",<br>             'fileTypeDesc':'图像文件',<br>             'fileTypeExts':'*.jpg; *.jpeg; *.gif; *.png',<br>                       “自动”:正确,<br>             'removeCompleted':假,<br>             onUploadSuccess:函数(文件、数据、响应){<br>                 $('#progress').hide();<br>                 var 结果 = $.parseJSON(data);<br>                 //错误处理。。。<br>                 if(结果.status == 0){<br>                     警报(结果.信息);<br>                     返回 false;<br>                 }<br>                 // 上传成功<br>                 var id = Math.random().toString();<br>                 id = id.replace('.','_'); //唯一生成标记<br>                 var html = '<li class="imageitem" id="'id '">';<br>                     html =''; //隐藏域,是为了把地址图片入库。。<br>                     html = '<input type="hidden" name="minifile[]" value="' result.mini_pic '">'; //隐藏域,是为了把图片地址入库。。<br />                    html = '<img height="160" width="160" src="__ROOT__/Uploads/' result.pic_path '" />';<br />                     html =  '<span class="txt">';<br />                     html =  '<a title="删除" href=javascript:remove("' result.pic_path '","' id '");><img  src="__PUBLIC__/assets/plugins/uploadify/remove. png" /></a>';<br alt="TP3.2:上传预览 缩略图 水印实例" >                     html =  '<a result.pic_path><img alt="TP3.2:上传预览 缩略图 水印实例" > ;</a>';<br>                     html =  '';<br>                     html =  '<em><input class="form-control" value="' file.name '"></em>';<br>                     html =  '</a> </li>';<br>                 $('#image_result').append(html);<br>             },<br>             onUploadStart:函数(){<br>                 $('#progress').text('正在上传...');  //等待用户提示。<br>             },<br>             onInit: 函数 (){  <br>                 $("#upload-queue").hide(); // 隐藏上传队列                <br>             }    <br>         }); <br>     });<br>     函数删除(文件,id){<br>         alert('删除成功!' "rn" 文件);<br>         $('#' id).remove();<br>     }<br>     函数覆盖(文件){<br>         alert('设为封面成功' "rn" file);<br>     }<br>     函数检查(){<br>         if($('input[name="title"]').val()==""){<br>             toastr['error']('标题不能为空!');<br>             返回 false;<br>         }<br>     }<br> <br>     </脚本><br> TP3.2:上传预览 缩略图 水印实例TP3.2:上传预览 缩略图 水印实例

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

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn