搜索 |
/**
* 上传文件
* @return [type] [description]
*/
public function upload(){
ini_set('memory_limit','288M');
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 20480000 ;// 设置附件上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->rootPath = './Uploads/'; // 设置附件上传根目录
$upload->subName = date("Ym",time())."/".date("Ymd",time());
$upload->savePath = 'yhpc/'; // 设置附件上传(子)目录
// 上传文件
$info = $upload->uploadOne($_FILES['upload_file']);
if(!$info) {// 上传错误提示错误信息
$this->error($upload->getError());
}else{// 上传成功
// $this->success('上传成功!');
$imgPath="./Uploads/".$info['savepath'].$info['savename'];
$imgPath=iconv("utf-8","gb2312",$imgPath);//★★★需要转换★★★
$image = new \Think\Image();
$image1 = new \Think\Image();
$image->open($imgPath);
$image1->open($imgPath);
$imgNewNameArr=explode(".",$info['savename']);
$imgNewName=$imgNewNameArr[0];
$imgNewName=iconv("utf-8","gb2312",$imgNewName);//★★★需要转换★★★
$imgNewExt=$imgNewNameArr[1];
$imgNewPathSmall="./Uploads/".$info['savepath']."small_".$imgNewName.".".$imgNewExt;
$image->thumb(80, 60,2)->save($imgNewPathSmall);
$imgNewPathBig="./Uploads/".$info['savepath']."big_".$imgNewName.".".$imgNewExt;
$image1->thumb(500, 360,2)->save($imgNewPathBig);
unlink($imgPath);//生成缩略图以后删除原图片
$fileinfo['message']='上传成功';
$fileinfo['status']=1;
$fileinfo['savepath']="/Uploads/".$info['savepath']."small_".$imgNewNameArr[0].".".$imgNewExt;
$this->ajaxReturn($fileinfo);
}
}