laravel文件上传customname

时间:2017-06-25 07:23:43

标签: php laravel-5

这是我的控制器将图像上传到mysql,它必须采用imge-> id和image-> name属性存储在db中。

use App\FileUpload;
    use Illuminate\Http\Request;
    class FileUploadController extends Controller
    {
        public function showUploadForm(){
          return view('upload.upload');
        }
        public function store(Request $request){
            if($request->hasFile('file')){
                //$imgFullname = new FileUpload;
                $imgFullname= $file->id . '.' . $file->name. '.'
                $request->file('file')->getClientOriginalExtension();
                $request->file->storeAs('public/upload', $imgFullname);
                $file = new FileUpload;
                $file->name = $fileName;
                $file->save();
                //return 'yes';
            }


}

enter image description here

1 个答案:

答案 0 :(得分:0)

你在行尾忘了;

use App\FileUpload;
    use Illuminate\Http\Request;
    class FileUploadController extends Controller
    {
        public function showUploadForm(){
          return view('upload.upload');
        }
        public function store(Request $request){
            if($request->hasFile('file')){
                //$imgFullname = new FileUpload;
                $imgFullname= $file->id . '.' . $file->name. '.'; //<---- add ; here
                $request->file('file')->getClientOriginalExtension();
                $request->file->storeAs('public/upload', $imgFullname);
                $file = new FileUpload;
                $file->name = $fileName;
                $file->save();
                //return 'yes';
            }


}