laravel - 错误调用 bool 上的成员函数 getRealPath()
问题描述
我收到此错误“调用 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();
解决方案
getRealPath()
是方法SplFileInfo
见:https ://www.php.net/manual/en/splfileinfo.getrealpath.php
如果你想使用getRealPath()
,试试这个:
Image::make(
$request->file('content')->getRealPath()
)->save('public/content',$fileNameToStore);
推荐阅读
- javascript - 在地图功能中反应条件渲染组件
- docker - docker run 后自动删除文件
- ios - iOS 编程:更详细地了解第一响应者
- javascript - 如何在 React.js 而不是 jQuery 或任何其他框架中获得选定的选项?
- java - 如何在springboot mongo-data中使用$in操作符
- javascript - React Modal 总是使用一行中的相同记录
- algorithm - A* 是否从边缘以增量成本顺序(如 Dijkstra 的)弹出节点以获得一致的启发式?
- swift - 如何对 SIMD3 进行类型转换
ARFaceGeometry 顶点坐标 - python - 如何使用 pandas .eval() 来评估多列上的操作。?
- html - 部署到 pythonanywhere.com 时未显示 Django 应用程序页面