public function doUpload(Request $request)
{
try{
$data = $request->all();
if(isset($data['image'])){
$dirName = 'Image';
$file = $data['image'] ?? null;
}else{
$dirName = 'Files';
$file = $data['file'] ?? null;
}
$content = file_get_contents($file);
$extension = $file -> getClientOriginalExtension();
$filePath ='/Upload/'.$dirName.'/'.date('Y-m-d');
$fullName = $filePath.'/'.time().random_int(100,999).'.'.$extension;
$oldumask=umask(0);
$this->directory(public_path().$filePath);
umask($oldumask);
file_put_contents(public_path().$fullName,$content);
$res =[
'path'=>$fullName,
'url'=>env('host_prefix','http://').$_SERVER['HTTP_HOST'].$fullName,
];
return $this->sendArrayResponse($res);
}catch (\Exception $e){
return $this->sendResponse(trans('system::system.error.upload'));
}
}
图片上传
于 2019-06-24 14:56:08 首次发布