使用 Laravel 使用 2 个磁盘复制文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47581934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Copying a file using 2 disks with Laravel
提问by prgrm
I have 2 disks in Laravel.
我在 Laravel 中有 2 个磁盘。
One is the local disk, the other one is a FTP server which I need to upload my files to. They are both correctly configured.
一个是本地磁盘,另一个是我需要将文件上传到的 FTP 服务器。它们都配置正确。
I have attempted it this way:
我已经这样尝试过:
Storage::disk('FTP')->copy('old/file1.jpg', 'new/file1.jpg');
This would only copy the file if it is already in the FTP server. I have also read the documentation and there seems to be no way to combine both in order to upload files.
如果文件已经在 FTP 服务器中,这只会复制文件。我也阅读了文档,似乎无法将两者结合起来上传文件。
Any suggestions?
有什么建议?
回答by Dan Jones
@ceejayoz has a good answer, but as mentioned in the comments, this fetches, and then writes.
@ceejayoz 有一个很好的答案,但正如评论中提到的,这会获取,然后写入。
In order to use streams, the following can be used instead:
为了使用流,可以使用以下内容:
Storage::disk('FTP')->writeStream('new/file1.jpg', Storage::readStream('old/file1.jpg'));
回答by ceejayoz
A simple combination of Storage::getand Storage::putshould do the trick.
一个简单的组合Storage::get和Storage::put应该做的伎俩。
Storage::disk('FTP')->put('new/file1.jpg', Storage::get('old/file1.jpg'));

