/**
* 缩略图上传
*/
public static function addPic()
{
$inputData = request()->all();
$rules = [
'main_img' => [ 'image','max:10240' ]
];
$validator = Validator::make($inputData,$rules);
if($validator->fails()){
return back()->withErrors($validator)->withInput();
}
$photo = $inputData['pic'];
$file_name = uniqid().'.'.$photo->getClientOriginalExtension();
$file_relative_path = '/pic/'.date('Y-m-d');
$file_path = public_path($file_relative_path);
if (!is_dir($file_path)){
mkdir($file_path);
}
$thumbnail_file_path = $file_path . '/thumb_'.$file_name;
$image = Image::make($photo)->resize(80, null, function ($constraint) {$constraint->aspectRatio();})->save($thumbnail_file_path);
$file_path .= '/'.$file_name;
$image = Image::make($photo)->save($file_path);
if($image)
{
return infoReturn(1,'',['src'=>$file_relative_path.'/'.$file_name]);
}else{
return infoReturn(0);
}
}