【问题标题】:Getting a Storage file and copying to another storage place获取存储文件并复制到另一个存储位置
【发布时间】:2018-01-09 16:31:23
【问题描述】:

所以,我保存了存储文件,可以像这样访问它们:

$file = Storage::disk('public')->url("featured/{$i->image}")

这让我获得了我在storage/ 目录中的文件的完整 URL。我怎样才能使它可以将相同的文件复制并粘贴到新目录但使用新文件名?

我试过了:

$url = Storage::disk('public')->url("featured/{$i->image}");
$fileName = 'u_' . (new \DateTime())->getTimestamp() . '.png';
$fileDestination = '/new_folder/' . $fileName;
$i->image = $fileDestination;
File::copy($url, $fileDestination);

我收到 PHP 执行超时错误。我认为我没有正确引用路径。

我想将/storage/app/public/featured/imageOne.png复制到/storage/app/public/new_folder/imageOneWITHNEWFILENAME.png

Storage门面解决方案吗?

【问题讨论】:

  • “但我总是遇到错误。” 比如?
  • 错误是什么?
  • 请显示$newDestination变量的值
  • 存储::copy($file, $newDestination);检查此链接laravel.com/docs/5.5/filesystem#storing-files
  • 我已经更新了一点。

标签: php laravel


【解决方案1】:

使用Storage 外观而不是File::copy 将文件复制到新的目的地,如

Storage::disk('public')->copy("featured/{$i->image}", $fileDestination);

参考:Laravel 5.5 file storage

【讨论】:

  • 得到File not found at path,即使我知道它在那里。里面storage/app/public。我的env APP_URL 是:http://localhost:8000
  • 这似乎是在复制,好像根是/public/featured,这不是我想要的。试图在这里找到一种方法......感谢这一点。
  • 啊,等我搞定了。我明白你的意思了。谢谢。
猜你喜欢
  • 2021-09-26
  • 2015-10-02
  • 2013-11-01
  • 1970-01-01
  • 2016-11-25
  • 1970-01-01
  • 2017-03-17
  • 2018-11-22
  • 1970-01-01
相关资源
最近更新 更多