对布尔型成员函数getRealPath()的错误调用

问题描述 投票:-1回答:1

我收到此错误“在布尔中调用成员函数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();
laravel
1个回答
0
投票

[getRealPath()SplFileInfo]的方法>

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

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

Image::make(
    $request->file('content')->getRealPath()
)->save('public/content',$fileNameToStore);
© www.soinside.com 2019 - 2024. All rights reserved.