我收到此错误“在bool上调用成员函数getRealPath()”
if($request->hasFile('content')) {
$filenameWithExt = $request->file('content')->getClientOriginalName();
$filename = pathinfo($filenameWithExt,PATHINFO_FILENAME);
$extension = $request->file('content')->getClientOriginalExtension();
$fileNameToStore = $filename.'_'.time().'.'.$extension;
$path = $request->file('content')->storeAs('public/content',$fileNameToStore);
} else {
$fileNameToStore = 'No Image,Music and Video selected please! check and try again.';
}
$post = new Post;
$post->body = $request->input('body');
$post->content = $fileNameToStore;
//Error exist here
$post = Image::make($fileNameToStore->getRealPath());
$post->text('The quick brown fox jumps over the lazy dog.');
$post->save();
答案 0 :(得分:0)
getRealPath()
是SplFileInfo
请参阅:https://www.php.net/manual/en/splfileinfo.getrealpath.php
如果您想使用getRealPath()
,请尝试以下操作:
Image::make(
$request->file('content')->getRealPath()
)->save('public/content',$fileNameToStore);