这是我的控制器将图像上传到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';
}
}
答案 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';
}
}