예제 #1
0
 /**
  * 上传图片
  */
 public function uploadPic()
 {
     $config = array('maxSize' => 0, 'exts' => array('jpg', 'png', 'gif', 'jpeg'), 'rootPath' => './Upload/', 'driver' => 'LOCAL', 'subName' => array('date', 'Y-m'), 'savePath' => I('dir', 'uploads') . "/");
     $upload = new \Think\Upload($config);
     $rs = $upload->upload($_FILES);
     if (!$rs) {
         $this->error($upload->getError());
     } else {
         $images = new \Think\Image();
         $images->open('./Upload/' . $rs['Filedata']['savepath'] . $rs['Filedata']['savename']);
         $newsavename = str_replace('.', '_thumb.', $rs['Filedata']['savename']);
         $vv = $images->thumb(I('width', 300), I('height', 300), I('thumb_type', 1))->save('./Upload/' . $rs['Filedata']['savepath'] . $newsavename);
         if (C('RTC_M_IMG_SUFFIX') != '') {
             $msuffix = C('RTC_M_IMG_SUFFIX');
             $mnewsavename = str_replace('.', $msuffix . '.', $rs[$Filedata]['savename']);
             $mnewsavename_thmb = str_replace('.', "_thumb" . $msuffix . '.', $rs[$Filedata]['savename']);
             $images->open('./Upload/' . $rs[$Filedata]['savepath'] . $rs[$Filedata]['savename']);
             $images->thumb(I('width', 700), I('height', 700))->save('./Upload/' . $rs[$Filedata]['savepath'] . $mnewsavename);
             $images->thumb(I('width', 250), I('height', 250))->save('./Upload/' . $rs[$Filedata]['savepath'] . $mnewsavename_thmb);
         }
         $rs['Filedata']['savepath'] = "Upload/" . $rs['Filedata']['savepath'];
         $rs['Filedata']['savethumbname'] = $newsavename;
         $rs['status'] = 1;
         echo json_encode($rs);
     }
 }
예제 #2
0
 function avatar()
 {
     $users_model = M("Users");
     $id = I("get.id", 0, "intval");
     $find_user = $users_model->field('avatar')->where(array("id" => $id))->find();
     $avatar = $find_user['avatar'];
     $image = new \Think\Image();
     $should_show_default = false;
     if (empty($avatar)) {
         $should_show_default = true;
     } else {
         if (strpos($avatar, "http") === 0) {
             header("Location: {$avatar}");
             exit;
         } else {
             $avatar_dir = C("UPLOADPATH") . "avatar/";
             $avatar = $avatar_dir . $avatar;
             if (file_exists($avatar)) {
                 $image->open($avatar);
                 $mime = $image->mime();
                 header("Content-type: {$mime}");
                 $image->save(null);
             } else {
                 $should_show_default = true;
             }
         }
     }
     if ($should_show_default) {
         $image->open("statics/images/headicon.png");
         $mime = $image->mime();
         header("Content-type: {$mime}");
         $image->save(null);
     }
     exit;
 }
예제 #3
0
 public function index()
 {
     if (!IS_POST) {
         date_default_timezone_set("Asia/Chongqing");
         error_reporting(E_ERROR);
         header("Content-Type: text/html; charset=utf-8");
         $CONFIG = json_decode(preg_replace("/\\/\\*[\\s\\S]+?\\*\\//", "", file_get_contents('.' . C('JS') . "ueditor1_4_3-utf8-php/php/config.json")), true);
         $action = I('get.action');
         switch ($action) {
             case 'config':
                 $result = json_encode($CONFIG);
                 echo $result;
                 break;
             case 'listimage':
                 $result = new \Vendor\Imageslist();
                 // 实例化上传类
                 echo $result;
                 break;
             default:
                 $this->display();
                 break;
         }
     } else {
         //本地配置
         $config = array('rootPath' => C('rootPath'), 'savePath' => '', 'saveName' => array('uniqid', ''), 'exts' => explode(',', C('upload_exts')), 'autoSub' => false);
         $type = 'Local';
         $upload = new \Think\Upload($config, $type);
         // 实例化上传类
         $info = $upload->upload();
         //print_r($info);
         if (!$info) {
             // 上传错误提示错误信息
             $this->error($upload->getError());
         } else {
             // 上传成功
             foreach ($info as $file) {
                 $imgurl = C('rootPath') . $file['savepath'] . $file['savename'];
                 $image = new \Think\Image();
                 if (C('IS_thumb') == '1') {
                     $image->open($imgurl);
                     $image->thumb(C('thumb_width'), C('thumb_height'), C('thumb_leixin'))->save($imgurl);
                 }
                 if (C('IS_water') == '1') {
                     if (C('water_lbs') == '10') {
                         $lbs = rand(1, 9);
                     }
                     $image->open($imgurl)->water('.' . C('water'), $lbs, C('water_touming'))->save($imgurl);
                 }
                 echo json_encode(array('status' => 1, 'error' => 0, 'url' => str_replace('./', '/', $imgurl), 'original' => $file['name'], 'state' => 'SUCCESS'));
             }
         }
     }
 }
예제 #4
0
function upload_one_thumb($param, $w = 680, $h = 250)
{
    $upload = new \Think\Upload();
    $upload->maxSize = 2097152;
    //字节 1KB=1024字节 默认为2M
    $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
    $upload->savePath = $param['savePath'];
    //保存路径 相对路径
    $upload->subName = $param['subName'];
    //子目录
    $upload->saveName = $param['saveName'];
    //保存名称
    $upload->saveExt = $param['saveExt'];
    //保存后缀
    $upload->replace = true;
    //存在同名的文件 覆盖
    $info = $upload->uploadOne($param['files']);
    if (!$info) {
        return 'error';
    } else {
        $img_src = './Uploads/' . $info['savepath'] . $info['savename'];
        $image = new \Think\Image();
        $image->open($img_src);
        //将图片裁剪为680X250并保存为
        $new_img_src = './Uploads/' . $info['savepath'] . 'thumb_' . $info['savename'];
        $image->crop($w, $h)->save($new_img_src);
        return $info['savepath'] . $info['savename'];
        //return $info['savepath'].'thumb_'.$info['savename'];
    }
}
예제 #5
0
 public function picAddHandle()
 {
     $config = array("savePath" => 'Weixin/', "maxSize" => 1000000, "exts" => array('jpg', 'gif', 'png', 'jpeg'), "subName" => array('date', 'Y/m-d'));
     $upload = new Upload($config);
     $info = $upload->upload();
     if (!$info) {
         // 上传错误提示错误信息
         $this->error($upload->getError());
     } else {
         // 上传成功 获取上传文件信息
         //   $file_path_full = Upload_PATH . $info['img']['savepath'] . $info['img']['savename'];
         $file_path_full = $info['img']['fullpath'];
         if (!defined('SAE_TMP_PATH')) {
             // 非SAE环境中
             $image = new \Think\Image();
             $image->open($file_path_full);
             $image->thumb(150, 150)->save($file_path_full);
             $img_url = "http://" . $_SERVER['SERVER_NAME'] . str_replace('index.php', '', __APP__) . $file_path_full;
         } else {
             // SAE环境中
             $img_url = $file_path_full;
         }
         $ACCESS_TOKEN = $this->getAccess();
         $post_data = array("media" => '@' . $file_path_full);
         $URL = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token={$ACCESS_TOKEN}&type=image";
         $res = json_decode(simple_post($URL, $post_data), true);
         $data['type'] = $res['type'];
         $data['mediaId'] = $res['media_id'];
         $data['picurl'] = $img_url;
         $res = D('Weixinre')->data($data)->add();
         if ($res) {
             $this->success('上传成功!', U('Weixin/Reply/index'));
         }
     }
 }
 public function submitSignup()
 {
     $upload = new \Think\Upload(C("UPLOAD_USER_PICS_CONFIG"));
     $info = $upload->uploadOne($_FILES['upic']);
     if (!$info) {
         $this->error($upload->getError());
     } else {
         dump($info);
         $image = new \Think\Image();
         $image->open(C("UPLOAD_USER_PICS_CONFIG.rootPath") . $info['savepath'] . $info['savename']);
         $thumb_url = C("UPLOAD_USER_PICS_CONFIG.rootPath") . $info['savepath'] . 'thumb_' . $info['savename'];
         $image->thumb(C("THUMB_USER_PIC_WIDTH"), C("THUMB_USER_PIC_HEIGHT"))->save($thumb_url);
         $_POST['upic'] = $info['savename'];
     }
     $_POST['upwd'] = I("upwd", "", md5);
     if (M("User")->create()) {
         $uid = M("User")->add();
         if ($uid) {
             session("uid", $uid);
             session('uname', I('uname'));
             $this->redirect("Index/index");
         }
     }
     $this->error("注册失败");
 }
예제 #7
0
 public function uploads()
 {
     $upload = new \Think\Upload();
     $upload->maxSize = 3145728;
     //设置上传图片大小
     $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
     //设置附件上传类型
     $upload->savePath = "Photo";
     //上传(子)目录
     $info = $upload->upload();
     //上传文件
     if (!$info) {
         $this->error($upload->getError());
     }
     //保存图片名
     $_POST['photo_name'] = $info['photo_name']['savepath'] . $info['photo_name']['savename'];
     $_POST['uid'] = $_SESSION['user']['id'];
     //用户id
     //生成缩略图
     $image = new \Think\Image();
     $bigimage = $info['photo_name']['savepath'] . $info['photo_name']['savename'];
     $srcimg = $upload->rootPath . $bigimage;
     $image->open($srcimg);
     $image->thumb(250, 150, \Think\Image::IMAGE_THUMB_CENTER);
     $smallimage = $info['photo_name']['savepath'] . 'thumb_' . $info['photo_name']['savename'];
     $image->save($upload->rootPath . $smallimage);
     $_POST['photo_name_thumb'] = $smallimage;
 }
예제 #8
0
 public function edit()
 {
     //实例化上传类
     $upload = new \Think\Upload();
     $upload->maxSize = 3145728;
     //设置上传图片大小
     $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
     //设置附件上传类型
     $upload->savePath = "First";
     //上传(子)目录
     $info = $upload->upload();
     //上传文件
     if (!$info) {
         $this->error($upload->getError());
     }
     //保存图片名
     $data['first'] = $info['first']['savepath'] . $info['first']['savename'];
     $data['uid'] = $_SESSION['user']['id'];
     //用户id
     //生产缩略图
     $image = new \Think\Image();
     $bigimage = $info['first']['savepath'] . $info['first']['savename'];
     $srcimg = $upload->rootPath . $bigimage;
     $image->open($srcimg);
     $image->thumb(250, 180, \Think\Image::IMAGE_THUMB_CENTER);
     $smallimage = $info['first']['savepath'] . 'thumb_' . $info['first']['savename'];
     $image->save($upload->rootPath . $smallimage);
     $id = $_POST['id'];
     $album = D('Album');
     $album->where(array('id' => $id))->setField('first', $smallimage);
     $this->redirect('Album/index');
 }
예제 #9
0
 public function ajax()
 {
     error_reporting(0);
     $userimgurl = I('post.pho');
     unlink('./Public/image/user/' . $userimgurl);
     $upload = new \Think\Upload();
     // 实例化上传类
     $upload->maxSize = 3145728;
     // 设置附件上传大小
     $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
     // 设置附件上传类型
     $upload->rootPath = './Public/image/user/';
     // 设置附件上传根目录
     $info = $upload->upload();
     if (!$info) {
         // 上传错误提示错误信息
         $this->error($upload->getError());
     } else {
         // 上传成功
         $userimgurl = $info['photo']['savepath'] . $info['photo']['savename'];
         $image = new \Think\Image();
         $image->open('./Public/image/user/' . $userimgurl);
         $image->thumb(180, 180, 3)->save('./Public/image/user/' . $userimgurl);
         $this->ajaxReturn($userimgurl);
     }
 }
예제 #10
0
파일: function.php 프로젝트: bjjfsd/CMS-TP
/**
 * 获取图片
 * @param
 * @return  string
 */
function thumb($img = '', $width = 0, $height = 0)
{
    if (empty($img)) {
        return __ROOT__ . '/default.jpg';
    }
    $Uploads = '/Uploads/';
    $file = '.' . $Uploads . $img;
    if (file_exists($file)) {
        if (empty($width)) {
            return __ROOT__ . substr($file, 1);
        } else {
            $pathinfo = pathinfo($file);
            $thumb_file = $pathinfo['dirname'] . '/' . $pathinfo['filename'] . '_' . $width . '-' . $height . '.' . $pathinfo['extension'];
            if (file_exists($thumb_file)) {
                return __ROOT__ . substr($thumb_file, 1);
            } else {
                $image = new \Think\Image();
                $image->open($file);
                if (empty($height)) {
                    $height = $image->height();
                }
                $image->thumb($width, $height, \Think\Image::IMAGE_THUMB_CENTER)->save($thumb_file);
                return __ROOT__ . substr($thumb_file, 1);
            }
        }
    }
    return __ROOT__ . '/default.jpg';
}
 /**
  * [处理系统配置文件修改]
  */
 public function ModSysHandle()
 {
     $upload = new \Think\Upload();
     // 实例化上传类
     $upload->rootPath = "./Public/";
     //rootPath这个路径必须手动创建
     $upload->savePath = "Logo/";
     //这一块只能设置一层目录
     $info = $upload->upload();
     if ($info) {
         // 上传成功 获取上传文件信息
         $image = new \Think\Image();
         $image->open('./Public/' . $info['face']['savepath'] . $info['face']['savename']);
         // 按照原图的比例生成一个最大为150*150的缩略图并保存为thumb.jpg
         $image->thumb(230, 45)->save('./Public/Logo/Logo.png');
     }
     $post = $_POST;
     $str = file_get_contents('Application/Common/Conf/config.php');
     //将配置文件中内容读出
     foreach ($post as $key => $val) {
         if (in_array($key, array_keys(C()))) {
             //判断键值是否存在于配置文件中
             $zz[] = "/'{$key}'\\s*.*?,\\n/i";
             $rep[] = "'{$key}' => '{$val}',\n";
         }
     }
     $str = preg_replace($zz, $rep, $str);
     //在str中匹配  然后替换
     //将修改后的文件重新写入到配置文件中
     if (file_put_contents('Application/Common/Conf/config.php', $str)) {
         //$this->success('修改成功',U('System/index'),3);
         $this->success('修改成功');
     }
 }
예제 #12
0
 public function upload()
 {
     $x1 = I("x1");
     $y1 = I("y1");
     $upload = new \Think\Upload();
     $upload->maxSize = 3145728;
     // 设置附件上传大小
     $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
     // 设置附件上传类型
     $upload->rootPath = 'Public/';
     $upload->savePath = 'Uploads/';
     $info = $upload->uploadOne($_FILES['member_pic']);
     if (!$info) {
         // 上传错误提示错误信息
         $this->error($upload->getError());
     } else {
         // 上传成功 获取上传文件信息
         $member_pic = $info['savepath'] . $info['savename'];
     }
     $member_p = "./Public/" . $info['savepath'] . $info['savename'];
     $image = new \Think\Image();
     $image->open($member_p);
     $image->crop(128, 128, $x1, $y1)->save($member_p);
     $memberdetail = M("Memberdetail");
     if ($memberdetail->create()) {
         $memberdetail->member_pic = $member_pic;
         $memberdetail->save();
         $_SESSION['member_pic'] = $member_pic;
         $this->success("头像修改成功!", U("avatar"));
     } else {
         $this->error("头像修改失败!", U("avatar"));
     }
 }
예제 #13
0
 public function ajaximgupload()
 {
     $path = 'uploadfiles/images/' . date('Y-m-d', time()) . '/';
     techan_mkdir($path);
     $info = $this->_upload($path);
     $newimg = './' . $path . $info['licensepath']['savename'];
     $thumb = './' . $path . 'thumb_' . $info['licensepath']['savename'];
     $backimg = '/' . $path . 'thumb_' . $info['licensepath']['savename'];
     $ttf = './ThinkPHP/ThinkPHP/Library/Think/Verify/ttfs/1.ttf';
     //水印字体
     $logo = './Public/images/face.png';
     //水印logo
     $image = new \Think\Image();
     //  $image->open($newimg)->text('Zhou',$ttf,20,'#000000',\Think\Image::IMAGE_WATER_SOUTHEAST)->thumb(242, 163,\Think\Image::IMAGE_THUMB_FILLED)->save($thumb);
     $image->open($newimg)->water($logo, \Think\Image::IMAGE_WATER_NORTHWEST)->thumb(242, 163, \Think\Image::IMAGE_THUMB_FILLED)->save($thumb);
     $data['imgurl'] = $backimg;
     $data['filesize'] = $info['licensepath']['size'];
     $data['fileext'] = $info['licensepath']['ext'];
     $data['width'] = '242';
     $data['height'] = '163';
     $data['addtime'] = time();
     $data['username'] = session('_proxyname');
     $data['ip'] = get_client_ip();
     $backid = $this->img_upload->add($data);
     if ($backid) {
         @unlink($newimg);
         $arr['imgurl'] = $backimg;
         $arr['backid'] = $backid;
         echo json_encode($arr);
     }
 }
예제 #14
0
 /**
  * uploadify图片上传
  */
 public function uploadify()
 {
     if (!empty($_FILES)) {
         //图片上传设置
         $config = array('maxSize' => C('UPLOAD_MAX_SIZE'), 'savePath' => '', 'saveName' => array('uniqid', ''), 'exts' => C('UPLOAD_EXTS'), 'autoSub' => true, 'subName' => array('date', 'Y-m-d'));
         $upload = new \Think\Upload($config);
         // 实例化上传类
         $images = $upload->upload();
         //判断是否有图
         if ($images) {
             $info = C('UPLOAD_PATH') . $images['Filedata']['savepath'] . $images['Filedata']['savename'];
             $miinfo = $info . '.mini.' . $images['Filedata']['ext'];
             $image = new \Think\Image();
             $image->open('./' . $info)->thumb(150, 150, \Think\Image::IMAGE_THUMB_CENTER)->save('./' . $miinfo);
             //添加图片水印
             //$image->open('./'.$info)->water('./Data/logo.png',\Think\Image::IMAGE_WATER_NORTHWEST,50)->save('./'.$info);
             //添加文字水印
             //$image->open('./'.$info)->text('姜医生','./Data/1.ttf',20,'#000000',\Think\Image::IMAGE_WATER_SOUTHEAST)->save($info);
             $data = array('status' => 1, 'path' => array('mini' => $miinfo, 'origin' => $info));
             $this->ajaxReturn($data);
         } else {
             $this->error($upload->getError());
             //获取失败信息
         }
     }
 }
 /**
  * 上传图片
  * @author huajie <*****@*****.**>
  */
 public function uploadPicture()
 {
     /* 返回标准数据 */
     $return = array('status' => 1, 'info' => '上传成功', 'data' => '');
     /* 调用文件上传组件上传文件 */
     $Picture = D('Picture');
     $pic_driver = C('PICTURE_UPLOAD_DRIVER');
     $info = $Picture->upload($_FILES, C('PICTURE_UPLOAD'), C('PICTURE_UPLOAD_DRIVER'), C("UPLOAD_{$pic_driver}_CONFIG"));
     //TODO:上传到远程服务器
     /* 记录图片信息 */
     if ($info) {
         $return['status'] = 1;
         $return = array_merge($info['download'], $return);
     } else {
         $return['status'] = 0;
         $return['info'] = $Picture->getError();
     }
     //如果开启水印
     if ($config['img_water_on'] == 2) {
         /*添加水印*/
         $config['img_water_on'] = get_config('IMG_WATER_ON');
         $config['img_water'] = get_product_image(get_config('IMG_WATER'));
         $config['img_water_postion'] = get_config('IMG_WATER_POSTION');
         $img_path = '.' . $info['download']['path'];
         $image = new \Think\Image();
         $image->open($img_path)->water('.' . $config['img_water'], $config['img_water_postion'])->save($img_path);
     }
     $this->ajaxReturn($return);
 }
예제 #16
0
파일: function.php 프로젝트: LynQJ/TourPro
function get_thumb($url, $width, $height)
{
    $name = end(explode("/", $url));
    $image = new \Think\Image();
    $image->open($url);
    $image->thumb($width, $height, \Think\Image::IMAGE_THUMB_CENTER)->save($name);
    return $name;
}
예제 #17
0
function savepic($filename)
{
    $picpath = './Public/upimage/' . $filename;
    $image = new \Think\Image();
    $image->open('./Public/upimage/' . $filename);
    $image->save('./Public/allimage/' . $filename);
    unlink($filename);
}
예제 #18
0
 /**
  * @param $cate
  * @return mixed
  */
 public function addAtc($cate)
 {
     //$title = $this->title;
     $upload = new \Think\Upload($this->config);
     $upload->saveName = ['Common\\Model\\PicgridModel::picgridName'];
     //$_POST['author'];
     $upload->subName = ['Common\\Model\\PicgridModel::picgridSub'];
     //$_POST['author'];
     $info = $upload->upload();
     //$upload->saveName=$this->picgridName();
     $cate_atc = M('cate_atc');
     //引索存储
     $image = new \Think\Image();
     //制造缩略图
     if (!$info) {
         // 上传错误提示错误信息
         $this->error = $upload->getError();
     } else {
         // 上传成功 获取上传文件信息
         foreach ($info as $file) {
             //                $file['title'] = $_POST['title'];
             //                $file['content'] = $_POST['content'];
             $file = array_merge($file, I('post.'));
             $this->create($file);
             $atc_id = $this->add();
             if ($atc_id == false) {
                 $this->error = '存储失败';
                 return false;
             }
             $picName = './Public' . $file['savepath'] . $file['savename'];
             $picThunbName = './Public' . $file['savepath'] . 'thumb/' . $file['savename'];
             chmod('./Public' . $file['savepath'], 0777);
             chmod($picName, 0777);
             //echo './Public/'.substr($file['savepath'],2).'thumb/hehe.jpg';
             $image->open($picName);
             if (!file_exists('./Public/' . $file['savepath'] . 'thumb')) {
                 mkdir('./Public' . $file['savepath'] . 'thumb');
                 chmod('./Public' . $file['savepath'] . 'thumb', 0777);
             }
             $image->thumb(500, 600)->save($picThunbName);
             chmod($picThunbName, 0777);
             $cate_atc->atc_id = $atc_id;
             $cate_atc->cate = $cate;
             $cate_atc->title = $_POST['title'];
             //$file['savename'] ;
             $cate_atc->createtime = date('y-m-d H:i:s');
             $cate_atc->model_id = $this->mid;
             $cate_atc->status = 1;
             if ($cate_atc->add()) {
                 return true;
             } else {
                 $this->delete($atc_id);
                 $this->error = '添加失败';
                 return false;
             }
         }
     }
 }
예제 #19
0
 public function filled($filename = 'logo1.png', $path = 'Public/images/')
 {
     // $path = ;
     // $filename = ;
     $image = new \Think\Image();
     // $image->open($path.$filename)->thumb(200,200,\Think\Image::IMAGE_THUMB_SCALE,false)->save($path.'thumb.png');//IMAGE_THUMB_FILLED
     $image->open($path . $filename)->thumb(200, 200, \Think\Image::IMAGE_THUMB_FILLED)->save($path . 'tmp.png');
     //IMAGE_THUMB_FILLED
     $this->show('<img src="http://' . $_SERVER['HTTP_HOST'] . '/' . $path . 'tmp.png">');
 }
예제 #20
0
 public function teacherImageCrop($path, $ext, $width, $height)
 {
     //$path是要处理的文件路径
     $image = new \Think\Image();
     $res = $image->open($path);
     //将图片裁剪为100x100并保存为corp.jpg
     $thumb_url = (string) time() . (string) rand() . '.' . $ext;
     $image->thumb($width, $height)->save('TeacherImages/thumb/' . $thumb_url);
     return $thumb_url;
 }
예제 #21
0
 public function update()
 {
     $id = I('id', 0, 'int');
     $mod = M('photo');
     $photo = M('photo')->where('id=' . $id)->find();
     unlink("./Public/Uploads/pic/" . $photo['url']);
     unlink("./Public/Uploads/pic/" . $photo['bigurl']);
     if ($_FILES['pic']['name'] != "") {
         $upload = new \Think\Upload();
         // 实例化上传类
         $upload->maxSize = 3145728;
         // 设置附件上传大小
         $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
         //设置附件上传类型
         $upload->rootPath = './Public/';
         // 设置附件上传根目录
         $upload->savePath = './Uploads/pic/';
         // 设置附件上传目录
         $upload->autoSub = true;
         //关闭子目录生成
         $upload->subName = array('date', 'Y-m-d');
         //子目录生成规则
         $info = $upload->upload();
         if (!$info) {
             echo $this->error($upload->getError());
         } else {
             //上传图片成功
             $time = date('Y-m-d');
             $file = $info['pic'];
             var_dump($_FILES['pic']);
             die;
             $_POST['bigurl'] = $time . "/" . $file['savename'];
             $pic = __ROOT__ . "/Public/" . $file['savepath'] . $file['savename'];
             $img = new \Think\Image();
             $img->open("./Public/" . $file['savepath'] . $file['savename']);
             $img->thumb(300, 300)->save("./Public/" . $file['savepath'] . "/s_" . $file['savename']);
             $_POST['url'] = $time . "/s_" . $file['savename'];
         }
         $_POST['time'] = time();
         if ($mod->create()) {
             $mod->save();
             $this->success("添加成功");
         } else {
             $this->success("添加失败");
         }
     } else {
         $_POST['time'] = time();
         if ($mod->create()) {
             $mod->save();
             $this->success("添加成功");
         } else {
             $this->success("添加失败");
         }
     }
 }
예제 #22
0
/**
 * 图片上传处理
 * @param $isThumb	是否需要缩略图,默认true
 * @return [type] [description]
 */
function uploadImg(&$data, $options, $isThumb = true)
{
    //设置上传文件的大小
    $iniFileSize = intval(ini_get('upload_max_filesize'));
    //1 php.ini配置文件的上传文件大小
    $localFileSize = C('MAX_FILE_SIZE');
    //2 获取配置文件中的自定义上传文件大小
    $allowFileSize = intval(min(iniFileSize, localFileSize));
    //3 获取最小值
    //设置上传根目录
    $rootPath = C('ROOT_IMG_PATH');
    //获取允许上传图片的后缀
    $ext = C('ALLOW_IMG_EXT');
    //设置配置信息
    $config = array('maxSize' => $allowFileSize * 1024 * 1024, 'rootPath' => $rootPath, 'savePath' => 'Goods/', 'saveName' => array('uniqid', ''), 'exts' => $ext, 'subName' => array('date', 'Ymd'), 'autoSub' => true);
    $upload = new \Think\Upload($config);
    // 实例化上传类
    $info = $upload->upload();
    //获取上传文件信息
    $filed = array_keys($info);
    //获取附件上传的表单name,对应数据表中的字段
    //var_dump($filed[0]);exit;
    //判断是否获取成功
    //上传错误信息4:代表没有文件上传
    if ($info) {
        //保存路径
        $imgName = $info[$filed[0]]['savepath'] . $info[$filed[0]]['savename'];
        //存入数据库
        $data[$filed[0]] = $imgName;
        //判断是否需要缩略图
        if ($isThumb) {
            //设置缩略图
            $image = new \Think\Image();
            //1 实例化Image对象
            $image->open($rootPath . $imgName);
            //2 获取图像文件进行操作
            //设置缩略图文件名
            $thumbImgName = $info[$filed[0]]['savepath'] . 'thumb_' . $info[$filed[0]]['savename'];
            //保存缩略图到指定路径
            $image->thumb(150, 150)->save($rootPath . $thumbImgName);
            //存入数据库
            $data['goods_thumb'] = $thumbImgName;
        }
        //存储完毕,返回真
        return array(true, '图片与缩略图上传成功');
    } else {
        $error = $upload->getError();
        // 获取上传的错误信息
        return array(false, $error);
        //$this->error = $error; // 然后通过模型的getError()方法获取错误信息
    }
}
예제 #23
0
 /**
  * swfupload 上传 
  */
 public function swfupload()
 {
     if (IS_POST) {
         //上传处理类
         $config = array('rootPath' => './' . C("UPLOADPATH"), 'savePath' => '', 'maxSize' => 11048576, 'saveName' => array('uniqid', ''), 'exts' => array('jpg', 'gif', 'png', 'jpeg', "txt", 'zip'), 'autoSub' => true);
         $upload = new \Think\Upload($config);
         //
         $info = $upload->upload();
         //开始上传
         if ($info) {
             //上传成功
             //写入附件数据库信息
             $first = array_shift($info);
             if (!empty($first['url'])) {
                 $url = $first['savepath'] . $first['url'];
             } else {
                 $url = C("TMPL_PARSE_STRING.__UPLOAD__") . $first['savepath'] . $first['savename'];
             }
             $textareaid = I('post.textareaid');
             if ('goods_photos' === $textareaid) {
                 // 商品缩略图
                 $bigimg = $first['savepath'] . $first['savename'];
                 $image = new \Think\Image();
                 $srcimg = $upload->rootPath . $bigimg;
                 $image->open($srcimg);
                 $site_options = get_site_options();
                 $image->thumb($site_options['goods_thumb_width'], $site_options['goods_thumb_height']);
                 $dirname = './' . C("UPLOADPATH_S") . $first['savepath'];
                 if (!is_dir($dirname)) {
                     mkdir($dirname);
                 }
                 $image->save($dirname . $first['savename']);
             }
             echo "1," . $url . "," . '1,' . $first['name'];
             exit;
         } else {
             //上传失败,返回错误
             exit("0," . $upload->getError());
         }
     } else {
         if (isset($_GET['file_upload_limit'])) {
             $file_upload_limit = I('get.file_upload_limit');
         } else {
             $file_upload_limit = 1;
         }
         $textareaid = I('get.textareaid');
         $this->assign('file_upload_limit', $file_upload_limit);
         $this->assign('textareaid', $textareaid);
         $this->display(':swfupload');
     }
 }
예제 #24
0
 public function cool()
 {
     //酷炫版
     $year = intval(I('get.y'));
     $years = $this->getYears();
     $this->commonassign();
     if (!$years) {
         $this->display('nodata');
     } else {
         $contestDB = D('Contest');
         if ($year <= 1960 || $year > 2037) {
             $data = $contestDB->field('MAX(YEAR(holdtime)) AS year')->where('type = 1')->find();
             $year = $data['year'];
         }
         $this->assign('y', $years);
         $this->assign('year', $year);
         if (intval($this->getconfig('config_contest_sort'))) {
             //按奖项优先排序
             $data = $contestDB->relation(true)->field('*, YEAR(holdtime) AS y, MONTH(holdtime) AS m')->where('type = 1 AND YEAR(holdtime) =' . $year)->order('medal ASC, holdtime DESC, team ASC')->select();
         } else {
             //按时间优先排序
             $data = $contestDB->relation(true)->field('*, YEAR(holdtime) AS y, MONTH(holdtime) AS m')->where('type = 1 AND YEAR(holdtime) =' . $year)->order('holdtime DESC, medal ASC, team ASC')->select();
         }
         import('ORG.Util.Image');
         for ($i = 0; $i < count($data); $i++) {
             $data[$i]['site'] = htmlspecialchars($data[$i]['site']);
             $data[$i]['university'] = htmlspecialchars($data[$i]['university']);
             $data[$i]['title'] = htmlspecialchars($data[$i]['title']);
             $data[$i]['team'] = htmlspecialchars($data[$i]['team']);
             $data[$i]['leader_detail']['chsname'] = htmlspecialchars($data[$i]['leader_detail']['chsname']);
             $data[$i]['leader_detail']['engname'] = htmlspecialchars($data[$i]['leader_detail']['engname']);
             $data[$i]['teamer1_detail']['chsname'] = htmlspecialchars($data[$i]['teamer1_detail']['chsname']);
             $data[$i]['teamer1_detail']['engname'] = htmlspecialchars($data[$i]['teamer1_detail']['engname']);
             $data[$i]['teamer2_detail']['chsname'] = htmlspecialchars($data[$i]['teamer2_detail']['chsname']);
             $data[$i]['teamer2_detail']['engname'] = htmlspecialchars($data[$i]['teamer2_detail']['engname']);
             //如果不存在缩略图,则生成
             if ($data[$i]['pic1'] && !file_exists('upload/thumb/' . substr($data[$i]['pic1'], 7))) {
                 $image = new \Think\Image();
                 $image->open($data[$i]['pic1'])->thumb(576, 360)->save('upload/thumb/' . substr($data[$i]['pic1'], 7));
             }
             if ($data[$i]['pic2'] && !file_exists('upload/thumb/' . substr($data[$i]['pic2'], 7))) {
                 $image = new \Think\Image();
                 $image->open($data[$i]['pic2'])->thumb(576, 360)->save('upload/thumb/' . substr($data[$i]['pic2'], 7));
             }
         }
         $this->assign('data', $data);
         $this->display('cool');
     }
 }
예제 #25
0
 public function examimg()
 {
     $upload = new \Think\Upload();
     $upload->maxSize = 3145728;
     $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
     $upload->savePath = 'examimg/';
     $info = $upload->upload();
     var_dump($info);
     $src = './Uploads/' . $info['img']['savepath'] . $info['img']['savename'];
     echo "<img src='" . $src . "''>";
     var_dump(extension_loaded());
     $image = new \Think\Image();
     $image->open($src);
     $image->thumb(300, 200)->save($src);
     echo "<img src='" . $src . "'' width='453' height='271'>";
 }
예제 #26
0
 public function CourseAddAction()
 {
     if (!IS_POST) {
         $this->error('非法请求', U('Index/index'));
     }
     $rules = array(array('course_name', 'require', '请填写课程名称', 0, '', 4), array('course_name', '0,12', '课程名称在12个字符以内', 0, 'length', 4), array('course_about', 'require', '请填写课程简介', 0, '', 4), array('course_about', '0,200', '课程名称在200个字符以内', 0, 'length', 4));
     $courseModel = M('course');
     $res = $courseModel->validate($rules)->create();
     if (!$res) {
         $this->ajaxReturn(get_ajax_res(0, '添加课程失败:' . $courseModel->getError()));
     }
     $rootPath = './Uploads/Course/';
     if (!is_dir($rootPath)) {
         mkdir($rootPath);
     }
     $upload = new \Think\Upload();
     // 实例化上传类
     $upload->maxSize = 2097152;
     // 设置附件上传大小
     $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
     // 设置附件上传类型
     $upload->rootPath = $rootPath;
     // 设置附件上传根目录
     $upload->autoSub = false;
     // 是否自动生成子目录
     // 上传文件
     $info = $upload->upload();
     // 返回错误提示消息
     if (!$info) {
         $this->ajaxReturn(get_ajax_res(0, '新增课程失败:' . $upload->getError()));
     }
     // 获取文件名和路径
     $imageName = $info['course_image']['savename'];
     $imagePath = $rootPath . $imageName;
     // 将课程信息写入数据库
     $courseModel->teacher_id = session('UID');
     $courseModel->course_image = $imageName;
     $courseModel->create_time = NOW_TIME;
     $courseModel->teacher_name = session('truename');
     $courseModel->add();
     // 处理课程缩略图
     $imageObject = new \Think\Image();
     $imageObject->open($imagePath);
     $imageObject->thumb(100, 100)->save($rootPath . $imageName);
     // 返回成功提示
     $this->ajaxReturn(get_ajax_res(1, '新增课程成功'));
 }
예제 #27
0
 public function insert()
 {
     if ($_SESSION['user']) {
         $Liuyan = new \Home\Controller\LiuyanController();
         $Liuyan->index();
         die;
     }
     $upload = new \Think\Upload();
     // 实例化上传类
     $upload->maxSize = 3145728;
     // 设置附件上传大小
     $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
     //设置附件上传类型
     $upload->rootPath = './Public/';
     // 设置附件上传目录
     $upload->savePath = './Uploads/pic/';
     // 设置附件上传目录
     $upload->autoSub = false;
     //关闭子目录生成
     // 上传文件
     $info = $upload->upload();
     if (!$info) {
         // 上传错误提示错误信息
         $this->error($upload->getError());
     } else {
         $file = $info['pic'];
         //获取当前文件的上传信息
         $pic = __ROOT__ . "/Public/" . $file['savepath'] . $file['savename'];
         //生产缩略图
         $img = new \Think\Image();
         $img->open("./Public/" . $file['savepath'] . $file['savename']);
         //$img->thumb(300,300)->save("./Public/".$file['savepath'].'c_'.$file['savename']);
         $img->thumb(100, 100)->save("./Public/" . $file['savepath'] . $file['savename']);
         $_POST['shengri'] = $_POST['ageyear'] . '-' . $_POST['agemonth'] . '-' . $_POST['ageday'];
         $_POST['password'] = md5($_POST['password']);
         $guest = D('guest');
         $_POST['bigpic'] = $file['savename'];
         $_POST['logintime'] = time();
         $guest->create();
         $id = $guest->add();
         $user = $guest->where('id=' . $id)->find();
         session('user', $user);
         $Liuyan = new \Home\Controller\LiuyanController();
         $Liuyan->index();
     }
 }
예제 #28
0
 /**
  * 生成缩略图
  * @param $pic 图片资源路径
  * @param null $path 保存路径
  * @param null $savename 图片名字
  */
 public function thumb($pic, $info = array())
 {
     $image = new \Think\Image();
     $image->open($pic);
     $image->thumb(380, 380);
     $savepath = APP_PATH . $info['path'];
     $name = 's_' . $info['name'];
     if (!is_dir($savepath)) {
         mkdir($savepath, 0, true);
     }
     $image->save($savepath . $name);
     $data = array();
     $data['name'] = $name;
     $data['path'] = $savepath;
     $data['pic_url'] = $info['savepath'] . $name;
     return $data;
 }
예제 #29
0
 public function cool()
 {
     //酷炫版
     $years = $this->getYears();
     $this->commonassign();
     if (!$years) {
         $this->display('nodata');
     } else {
         $this->assign('y', $years);
         $this->assign('nowyear', 9999);
         $contest = D('Contest');
         $data = $contest->relation(true)->field('*, YEAR(holdtime) AS y, MONTH(holdtime) AS m')->where('type=0')->order('holdtime DESC')->select();
         //如果不存在缩略图,则生成
         import('ORG.Util.Image');
         for ($i = 0; $i < count($data); $i++) {
             $data[$i]['site'] = htmlspecialchars($data[$i]['site']);
             $data[$i]['university'] = htmlspecialchars($data[$i]['university']);
             $data[$i]['title'] = htmlspecialchars($data[$i]['title']);
             $data[$i]['team'] = htmlspecialchars($data[$i]['team']);
             $data[$i]['leader_detail']['chsname'] = htmlspecialchars($data[$i]['leader_detail']['chsname']);
             $data[$i]['leader_detail']['engname'] = htmlspecialchars($data[$i]['leader_detail']['engname']);
             $data[$i]['teamer1_detail']['chsname'] = htmlspecialchars($data[$i]['teamer1_detail']['chsname']);
             $data[$i]['teamer1_detail']['engname'] = htmlspecialchars($data[$i]['teamer1_detail']['engname']);
             $data[$i]['teamer2_detail']['chsname'] = htmlspecialchars($data[$i]['teamer2_detail']['chsname']);
             $data[$i]['teamer2_detail']['engname'] = htmlspecialchars($data[$i]['teamer2_detail']['engname']);
             if (strtotime($data[$i]['holdtime']) > time()) {
                 $data[$i]['coming'] = 1;
             } else {
                 $data[$i]['coming'] = 0;
             }
             //已比赛
             //如果不存在缩略图,则生成
             if ($data[$i]['pic1'] && !file_exists('upload/thumb/' . substr($data[$i]['pic1'], 7))) {
                 $image = new \Think\Image();
                 $image->open($data[$i]['pic1'])->thumb(576, 360)->save('upload/thumb/' . substr($data[$i]['pic1'], 7));
             }
             if ($data[$i]['pic2'] && !file_exists('upload/thumb/' . substr($data[$i]['pic2'], 7))) {
                 $image = new \Think\Image();
                 $image->open($data[$i]['pic2'])->thumb(576, 360)->save('upload/thumb/' . substr($data[$i]['pic2'], 7));
             }
         }
         $this->assign('data', $data);
         $this->display('cool');
     }
 }
예제 #30
0
 public function crop($file, $x, $y, $width, $height)
 {
     $image = new \Think\Image();
     $image->open('.' . $file);
     //将图片裁剪为$widthx$height并保存为$tmp_file
     $tmp_file = date('Y_m_d_h_i_s') . '.' . $image->type();
     $local_file = './Uploads/tmp/' . $tmp_file;
     $image->crop($width, $height, $x, $y)->save($local_file);
     if (!is_file($local_file)) {
         $this->error('生成裁剪文件失败');
     }
     $res = local_upload($local_file, 'Picture');
     if ($res['status']) {
         $this->success('裁剪成功', '', $res);
     } else {
         $this->error($res['error']);
     }
 }