Exemplo n.º 1
0
 /**
  * 上传缩略图
  * @param null $path
  * @return array
  */
 public function uploadThumb($path = null)
 {
     $upload = new \Think\UploadFile();
     // 实例化上传类
     $upload->maxSize = 3000000;
     // 设置附件上传大小
     $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');
     // 设置附件上传类型
     $upload->allowTypes = array('image/jpg', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/gif');
     $upload->savePath = 'Public/Uploads/' . $path;
     // 设置附件上传目录
     $upload->saveRule = 'uniqid';
     $upload->thumb = true;
     $upload->thumbMaxWidth = '300';
     $upload->thumbMaxHeight = '300';
     $upload->thumbPrefix = 's_';
     $upload->thumbRemoveOrigin = false;
     if ($upload->upload()) {
         $info = $upload->getUploadFileInfo();
         return $info;
     }
 }
Exemplo n.º 2
0
 /**
  *处理图像上传函数
  * @param [String] $path 保存文件路径
  * @param [String] $width 保存的宽度
  * @param [String] $height 保存的高度
  * @return array 图片上传的信息
  */
 private function _upload($path, $width, $height)
 {
     $upload = new \Think\UploadFile();
     $upload->maxSize = C('UPLOAD_MAX_SIZE');
     // 设置附件上传大小  C('UPLOAD_SIZE');
     $upload->savePath = C('UPLOAD_PATH') . $path . '/';
     // 设置附件上传目录
     $upload->allowExts = C('UPLOAD_EXTS');
     // 设置附件上传类型
     $upload->saveRule = 'uniqid';
     //保存文件名
     $upload->uploadReplace = true;
     //是否存在同名文件是否覆盖
     //缩略图部分
     $upload->thumb = true;
     //是否对上传文件进行缩略图处理
     $upload->thumbMaxWidth = $width;
     //缩略图处理宽度
     $upload->thumbMaxHeight = $height;
     //缩略图处理高度
     $upload->thumbPrefix = 'max_,medium_,mini_';
     //生产2张缩略图
     $upload->thumbPath = $upload->savePath . date('Y_m_d') . '/';
     //缩略图保存路径
     $upload->thumbRemoveOrigin = true;
     //上传图片后删除原图片
     $upload->autoSub = true;
     //是否使用子目录保存图片
     $upload->subType = 'date';
     //子目录保存规则
     $upload->dateFormat = 'Y_m_d';
     //子目录保存规则为date时时间格式
     if (!$upload->upload()) {
         return array('status' => 0, 'msg' => $upload->getErrorMsg());
     } else {
         $info = $upload->getUploadFileInfo();
         $pic = explode('/', $info[0]['savename']);
         return array('status' => 1, 'path' => array('max' => $pic[0] . '/max_' . $pic[1], 'medium' => $pic[0] . '/medium_' . $pic[1], 'mini' => $pic[0] . '/mini_' . $pic[1]));
     }
 }
Exemplo n.º 3
0
 /**
  * 图片上传
  */
 public function yf_sign()
 {
     $res = array('error' => 1, 'content' => '上传失败', 'num' => 0, 'status' => false);
     $args = I('get.args');
     //参数验证码
     $authkey = I('get.authkey');
     //模块
     $module = I('get.module', 'item');
     $num = I('get.num', 0, 'intval');
     //  echo $module.$authkey;echo '---'.upload_key($args);die;
     //验证是否可以上传
     $info = $this->isUpload($module, $args, $authkey);
     if (true !== $info) {
         $status = false;
         $res['content'] = "上传验证失败";
     } else {
         $status = true;
     }
     if ($status) {
         include_once CORE_PATH . "UploadFile.class.php";
         $upload = new \Think\UploadFile();
         // 实例化上传类
         //$date =date('Ymd');
         $path = array('f', $module, date('y'), date('m'), date('d'));
         $yf_path = './';
         foreach ($path as $v) {
             $yf_path .= $v . '/';
             if (!is_dir($yf_path)) {
                 if (is_dir(base64_decode($yf_path))) {
                     $yf_path = base64_decode($yf_path);
                 } else {
                     if (!mkdir($yf_path)) {
                     }
                 }
             }
         }
         $upload->maxSize = 3145728;
         // 设置附件上传大小
         $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');
         // 设置附件上传类型
         $upload->allowTypes = array('image/jpg', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/gif');
         $upload->savePath = $yf_path;
         $upload->saveRule = 'uniqid';
         //缩略图配置
         $upload->thumb = true;
         $upload->thumbMaxWidth = '600';
         $upload->thumbMaxHeight = '400';
         $upload->thumbPrefix = 'yf_';
         $upload->thumbRemoveOrigin = false;
         $img_info = $upload->getImageSize();
         if ($img_info['filewidth'] < 600 || $img_info['fileheight'] < 400) {
             $res['content'] = "上传的尺寸不能小于600*400";
         } else {
             if (!$upload->upload()) {
                 // 上传错误提示错误信息
                 $res['content'] = "系统繁忙,上传失败";
             } else {
                 // 上传成功 获取上传文件信息
                 $res['error'] = 0;
                 $res['num'] = $num + 1;
                 $data = $upload->getUploadFileInfo();
                 $data[0]['path'] = str_replace("./", "/", $data[0]['savepath']);
                 $res['content'] = $data[0];
             }
         }
     }
     $res['status'] = $status;
     // jsonp callback
     $callback = I('get.callback');
     $this->ajaxReturn($res, isset($_GET['callback']) && $callback ? 'JSONP' : 'JSON');
     //echo json_encode(array('error' => 0));
 }