123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- /**
- * 小梦科技资源nanodreamtech.com
- *
- * ==========================================================================
- * @link https://www.nanodreamtech.com/
- * @copyright Copyright (c) 2015 liofis.com.
- * @license https://www.nanodreamtech.com/license.html License
- * ==========================================================================
- *
- * @author fish
- *
- */
- namespace Admin\Controller;
- class ImageController extends CommonController{
-
- //删除图片和缩略图
- public function del_image($dir,$image,$type){
-
- $image_dir=ROOT_PATH.'Uploads/image/'.$dir.'/';
- $thumb_dir=ROOT_PATH.'Uploads/image/cache/'.$dir.'/';
-
- list($base_name, $ext) = explode(".", $image);
- $image = explode("/", $base_name);
- $image_name=end($image);
- if($type=='product'){
- $del_image=array();
- $del_image[]=$image_dir.$image_name.'.'.$ext;//原图
- $del_image[]=$thumb_dir.$image_name.'-50x50.'.$ext;
- $del_image[]=$thumb_dir.$image_name.'-100x100.'.$ext;
- $del_image[]=$thumb_dir.$image_name.'-255x255.'.$ext;
- }elseif($type=='gallery'){
- $del_image=array();
- $del_image[]=$image_dir.$image_name.'.'.$ext;//原图
- $del_image[]=$thumb_dir.$image_name.'-100x100.'.$ext;
- $del_image[]=$thumb_dir.$image_name.'-127x127.'.$ext;
- }elseif($type=='blog'){
- $del_image=array();
- $del_image[]=$image_dir.$image_name.'.'.$ext;//原图
- $del_image[]=$thumb_dir.$image_name.'-100x100.'.$ext;
- $del_image[]=$thumb_dir.$image_name.'-280x140.'.$ext;
- }elseif($type=='blog_gallery'){
- $del_image=array();
- $del_image[]=$image_dir.$image_name.'.'.$ext;//原图
- $del_image[]=$thumb_dir.$image_name.'-100x100.'.$ext;
-
- }
- if(!empty($del_image)){
- foreach ($del_image as $k => $v) {
- if(is_file($v)){
- @unlink($v);
- }
- }
- }
- }
-
-
- /**
- *删除 旧的原图和缩略图,修改的情况下使用
- *
- */
- public function del_old_image(){
-
- $old_gallery_image=I('post.old_gallery_image');
- $old_product_image=I('post.old_product_image');
-
- if(!empty($old_gallery_image)){
- $old_image=I('post.old_gallery_image');
-
- $thumb_dir=ROOT_PATH.'Uploads/image/cache/gallery/';
- $image_dir=ROOT_PATH.'Uploads/image/gallery/';
-
- }elseif(!empty($old_product_image)){
- $old_image=I('post.old_product_image');
-
- $thumb_dir=ROOT_PATH.'Uploads/image/cache/product/';
- $image_dir=ROOT_PATH.'Uploads/image/product/';
-
- }
- if(!empty($old_image)){
-
- list($base_name, $ext) = explode(".", $old_image);
- $image = explode("/", $base_name);
- $image_name=end($image);
-
- $del_image=array();
- $del_image[]=$image_dir.$image_name.'.'.$ext;//原图
- $del_image[]=$thumb_dir.$image_name.'-100x100.'.$ext;//100x100
-
- foreach ($del_image as $k => $v) {
- if(is_file($v)){
- @unlink($v);
- }
- }
- }
- }
- /**
- *上传图片
- */
- public function upload_image(){
-
- $dir=I('get.dir');
- $dir .= '/'.date('Y-m-d');
-
- $this->del_old_image();
-
- $upload = new \Think\Upload();// 实例化上传类
-
- $image_dir=ROOT_PATH.'Uploads/image/'.$dir;
-
- RecursiveMkdir($image_dir);
-
-
- $upload->autoSub = false;
- $upload->maxSize = 3145728 ;// 设置附件上传大小
- $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
- $upload->rootPath = $image_dir.'/';
-
- $info = $upload->upload();
-
- if(!$info) {
- $data['result'] = false;
-
- $this->ajaxReturn($data);
- }else{// 上传成功
-
- $filename=$dir.'/'.$info['file']['savepath'].$info['file']['savename'];
- $data['image_thumb'] = resize($filename, 100, 100);
- $data['image'] = $filename;
- $this->ajaxReturn($data);
-
- }
- }
- //用于ckeditor图片上传
- function ckupload(){
- $upload = new \Think\Upload();// 实例化上传类
-
- $upload->maxSize = 3145728 ;// 设置附件上传大小
- $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
- $upload->rootPath = ROOT_PATH.'Uploads/image/goods_description/';
- RecursiveMkdir($upload->rootPath);
- $info = $upload->upload();
- if(!$info) {
- // 上传错误提示错误信息
- echo "<script type=\"text/javascript\">window.parent.CKEDITOR.tools.callFunction(".$_GET['CKEditorFuncNum'].", '/', '上传失败," . $upload->getError() . "!');</script>";
- }else{// 上传成功
- $n=$_GET['CKEditorFuncNum'];
- $savepath=C('SITE_URL').'/Uploads/image/goods_description/'. $info['upload']['savepath'].$info['upload']['savename'];
- //下面的输出,会自动的将上传成功的文件路径,返回给编辑器。
- echo "<script type=\"text/javascript\">window.parent.CKEDITOR.tools.callFunction(".$n.",'$savepath','');</script>";
- }
-
- }
-
- }
|