存储中的文件和数据库中的不同名称
在该数据库中存储名称之后,我已经使用存储立面将文件存储在公共存储中,但是字段的名称不同吗?那么,如何在公共存储和数据库中以相同名称存储它们呢? ,我在下面使用此代码:
if($request->hasFile('file')) {
$image = $request->file('file');
$imageName = $image->getClientOriginalName();
Storage::disk('public')->put('images', $image);
Post::create([
'title' => $request->input('title'),
'content' => $request->input('content'),
'user_id' => Auth::id(),
'file' => $imageName,
]);
在存储此名称的存储中:ejn0y8flfggfggfjlleussig6eo4lb3oneigoxloijv.png 并在存储原始名称的数据库中
i have used Storage Facade to store the file in the public storage, after that store the name in the database, but the name of the field are different? so how can store them in the same name in both public storage and database? , I have use this code below:
if($request->hasFile('file')) {
$image = $request->file('file');
$imageName = $image->getClientOriginalName();
Storage::disk('public')->put('images', $image);
Post::create([
'title' => $request->input('title'),
'content' => $request->input('content'),
'user_id' => Auth::id(),
'file' => $imageName,
]);
in the storage stored with this name: ejn0Y8flFGGfjllEussig6EO4LB3onEIGoXlOIJV.png
and in the database stored with the original name
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 putfileas 。文件名为第三个param。
参考:自动流
use putFileAs.so you can pass custom file name as third param.
Ref: Automatic Streaming