【发布时间】:2018-12-06 00:13:50
【问题描述】:
我在使用 System/Models/File 时尝试保留原始文件名,我得到以下代码来扩展此模型:
namespace System\Models;
class NewFile extends File { public function fromPost($uploadedFile) { if ($uploadedFile === null) { return; }
$this->file_name = $uploadedFile->getClientOriginalName();
$this->file_size = $uploadedFile->getClientSize();
$this->content_type = $uploadedFile->getMimeType();
$this->disk_name = $this->getDiskName();
/*
* getRealPath() can be empty for some environments (IIS)
*/
$realPath = empty(trim($uploadedFile->getRealPath()))
? $uploadedFile->getPath() . DIRECTORY_SEPARATOR . $uploadedFile->getFileName()
: $uploadedFile->getRealPath();
//$this->putFile($realPath, $this->disk_name);
$this->putFile($realPath, $this->file_name);
return $this;
它适用于文件本身,它保留原始名称,但问题是仍在生成附加文件的链接。打破了我的想法,但无法完成这项工作。谁能详细说明如何解决?
【问题讨论】:
-
but the problem is a link to an attached file is still being generated表示您需要什么 - 停止生成链接或者它没有正确生成? -
我的意思是它仍然是由原始十月 CMS 方法生成的。例如,上传图片的文件路径为site.com/storage/app/uploads/public/5b3/74f/e7b/5b374fe7b9856296467891.png,但实际图片保存在site.com/storage/app/uploads/public/5b3 /74f/e7b/logo.png
标签: laravel extend octobercms