//图片上传 调用上传前一定要确定有文件,否则会出错
public function image($file,$controller,$method)
{
// 调用上传前一定要确定有文件,否则会出错
// if ($file == null ){
// $this->error('获取图片失败','article/add');
// }
$dir = ROOT_PATH.'public/uploads';
if (!is_dir($dir)){
mkdir($dir);
}
$info = $file->move($dir);
// $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
$ext = strtolower($info->getExtension());
if (!in_array($ext,array('jpg','gif','png','jpeg'))){
$this->error('图片格式不支持',"$controller/$method");
}
$res = "/uploads/".$info->getSaveName();
return $res;
}
图片上传类
关注
打赏