In the laravel framework, an error is always reported when accepting files uploaded by inputs. The detailed code is as follows:
use Illuminate\Http\Request;
public function file(){
$file = Request::file('photo');
$allowed_extensions = ["png", "jpg", "gif"];
if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) {
return ['error' => 'You may only upload png, jpg or gif.'];
}
}
The error is reported as follows:
1. Request usage error: Non-static method Illuminate\Http\Request::file() should not be called statically, assuming $this from incompatible context
2. Wrong use of getClientOriginalExtension()Call to a member function getClientOriginalExtension() on string
I hope God can give me some advice, urgent! ! !
Your Request class reference is wrong, it should be in supportfacades.