在布尔上错误调用成员函数getRealPath()

时间:2019-11-09 05:04:49

标签: laravel

我收到此错误“在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();

1 个答案:

答案 0 :(得分:0)

getRealPath()SplFileInfo

的方法

请参阅:https://www.php.net/manual/en/splfileinfo.getrealpath.php

如果您想使用getRealPath(),请尝试以下操作:

Image::make(
    $request->file('content')->getRealPath()
)->save('public/content',$fileNameToStore);