laravel接受文件

在laravel框架中接受inputs上传的文件一直报错,详细代码如下:

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.'];
         }
 
    }

报错如下:
1、Request使用错误:
Non-static method Illuminate\Http\Request::file() should not be called statically, assuming $this from incompatible context
2、getClientOriginalExtension()使用错误
Call to a member function getClientOriginalExtension() on string

希望大神指教,急急急!!!

阅读 3.9k
1 个回答

你的Request类引用错了,应该是support\facades\中的。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题