在Laravel 8中,如何使用Storage将文件从一个磁盘复制到另一个磁盘?
In Laravel 8, how to copy a file from one disk to another using Storage?
在config\filesystems.php
中配置了一个磁盘(这是正确连接的VPS。)我称之为vps_disk
。通过以下方式我可以获得文件:
$file = Storage::disk('vps_disk')->get('/path/to/file');
问题是我无法将此文件保存在本地磁盘上(而且还更改了它的名称)。我这样尝试失败:
$save_file = $file->storeAs('/', $filename, 'local_disk');
这就是我得到的错误:
Call to a member function storeAs() on string
下面一行代码正确returns文件内容:
$content = Storage::disk('vps_disk')->get('/path/to/file');
这里是将文件保存到本地磁盘的方法:
Storage::put('path/to/file/'.$filename_with_extension, $content);
在config\filesystems.php
中配置了一个磁盘(这是正确连接的VPS。)我称之为vps_disk
。通过以下方式我可以获得文件:
$file = Storage::disk('vps_disk')->get('/path/to/file');
问题是我无法将此文件保存在本地磁盘上(而且还更改了它的名称)。我这样尝试失败:
$save_file = $file->storeAs('/', $filename, 'local_disk');
这就是我得到的错误:
Call to a member function storeAs() on string
下面一行代码正确returns文件内容:
$content = Storage::disk('vps_disk')->get('/path/to/file');
这里是将文件保存到本地磁盘的方法:
Storage::put('path/to/file/'.$filename_with_extension, $content);