php - laravel接受文件
ringa_lee
ringa_lee 2017-05-17 09:55:47
0
1
593

在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

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

ringa_lee
ringa_lee

ringa_lee

全部回覆(1)
仅有的幸福

你的Request類別引用錯了,應該是supportfacades中的。

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!