<input type="file" name="photo" />




use Illuminate\Http\Request;
public function postPublish(Request $request){
$userid = Auth::user()->pk_id;
$title = $request->get('col_title');
$message = $request->get('col_message');
$file = $request->file('photo');
if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) {
return ['error' => '只能上传png,jpg,gif格式。'];
}
 $destinationPath = 'storage/uploads/'; //上传位置
$extension = $file->getClientOriginalExtension();
$fileName = str_random(10).'.'.$extension;
$file->move($destinationPath, $fileName);
$filePath = asset($destinationPath.$fileName);
//保存到数据库
if(CompanyInformation::createInformation($userid,$filePath,$title,$message))
return redirect('/abc');
else
return Redirect::back()->withInput()->withError(['error' => '保存失败']);
}


相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
猜你喜欢
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
  • 2022-03-10
  • 2021-11-25
  • 2022-12-23
相关资源
相似解决方案