存储中的文件和数据库中的不同名称

发布于 2025-02-08 08:30:22 字数 630 浏览 3 评论 0原文

在该数据库中存储名称之后,我已经使用存储立面将文件存储在公共存储中,但是字段的名称不同吗?那么,如何在公共存储和数据库中以相同名称存储它们呢? ,我在下面使用此代码:

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光清浅 2025-02-15 08:30:22

使用 putfileas 。文件名为第三个param。

Storage::disk('public')->putFileAs('images',$image, $imageName);

参考:自动流

use putFileAs.so you can pass custom file name as third param.

Storage::disk('public')->putFileAs('images',$image, $imageName);

Ref: Automatic Streaming

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文