gpt4 book ai didi

local-storage - Laravel 5.4 : save files with real name

转载 作者:行者123 更新时间:2023-12-04 06:06:58 25 4
gpt4 key购买 nike

我用 Storage::disk('local')->put('myfiles/',$request->file)将文件保存在磁盘上。但Storage使用散列名称保存文件。
如果你看一下源码put返回 putFileAs在最后一步:

 public function putFile($path, $file, $options = [])
{
return $this->putFileAs($path, $file, $file->hashName(), $options);
}

如您所见,文件名是由 laravel 创建的。
有没有办法用真实的文件名在服务器上保存文件?

最佳答案

看看laravel docs

检索上传文件的原始名称

$name = Input::file('photo')->getClientOriginalName();

试试这个: $request->getClientOriginalName();
编辑

一起保存这样
Storage::disk('local')->put('myfiles/' . $request->getClientOriginalName() . $request->getClientOriginalExtension() ,$request->file) 

编辑2

尝试使用 PutFileAs laravel docs 中描述的方法

关于local-storage - Laravel 5.4 : save files with real name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42693133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com