public function uploadFace(){
if (IS_POST) {
$upload = $this->_upload('Face', '100,60', '100,60');
echo json_encode($upload);
}else {
$this->error('无法上传');
}
}
/**
* 图片上传处理
* @param [String] $path [保存文件夹名称]
* @param [String] $width [缩略图宽度多个用,号分隔]
* @param [String] $height [缩略图高度多个用,号分隔(要与宽度一一对应)]
* @return [Array] [图片上传信息]
*/
Private function _upload ($path, $width, $height) {
$obj =new \Think\Upload(); //实例化上传类
$obj->maxSize = C('UPLOAD_MAX_SIZE'); //图片最大上传大小
$obj->savePath = $path . '/'; //图片保存路径
$obj->saveName=array('uniqid',''); //保存文件名
$obj->replace = true; //覆盖同名文件
$obj->exts = C('UPLOAD_EXTS'); //允许上传文件的后缀名
$obj->autoSub = true; //使用子目录保存文件
$obj->subName = array('date','Y-m-d'); //使用日期为子目录名称
$info = $obj->upload();
if (!$info) {
return array('status' => 0, 'msg' => $obj->getErrorMsg());
}else {
//生成缩略图
foreach($info[0] as $key=>$file) {
$thumb_file=$file['savepath'].$file['savename'];
$save_path =array(
$file['savepath'].'max_'.$file['savename'],
$file['savepath'].'mini_'.$file['savename']
);
$image =new \Think\Image();
$image->open($thumb_file);
$image->thumb($width, $height,\Think\Image::IMAGE_THUMB_FILLED)->save($save_path);
return array(
'status' => 1,
'path' => array(
'max'=>$file['savepath'].'/max_'.$file['savename'],
'mini'=>$file['savepath'].'/mini_'.$file['savename']
)
);
@unli
}}
}
最佳答案