可能很简单,但我在谷歌或这里找不到任何正确的答案!!
我确实用过
\File::copyDirectory('public/' . $token . '/cover/', $folderName . '/cover/');
但是没有什么不同!!
你知道如何使用 laravel 5.4 将整个目录从一个文件夹复制到另一个文件夹吗?
提前致谢
一年多过去了:)
使用路径助手函数https://laravel.com/docs/5.6/helpers
\File::copyDirectory( public_path . 'to/the/app', resource_path('to/the/app'));
我们可以在 Laravel 5.8 中使用文件门面来做到这一点,如下所示:
use Illuminate\Support\Facades\File;
File::copyDirectory(__DIR__.'/form-directory', resource_path('to-directory'));
希望,这会有所帮助。
就这样做:
/* Move test images from public folder to storage folder */
$source = "source/path";
$destination = "public/files";
File::copyDirectory(base_path($source), base_path($destination));
我使用了存储立面并且效果很好
config/filesystems.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => public_path(),
],
...
]
将所有文件从 public/seed_images/ 复制到 public/images/
应用程序/Http/Controllers/HomeController.php
use Illuminate\Support\Facades\Storage;
$fromFiles = Storage::allFiles('seed_images');
for ($i=0; $i < count($fromFiles) ; $i++) {
$toFile = str_replace("seed_images","images",$fromFiles[$i]);
Storage::copy( $fromFiles[$i], $toFile );
}
/**
* If the destination directory does not actually exist, we will go
* ahead and create it recursively, which just gets the destination
* prepared to copy the files over. Once we make the directory we'll
* proceed the copying.
*
* function replaces files with same names
*
* @var bool
*/
$result = File::copyDirectory(
base_path() . '/storage/source',
base_path() . '/storage/destination'
);
尝试使用 mix.copy() 方法。
mix.copy('public/' . $token . '/cover/', $folderName . '/cover/');
了解更多信息:https://laravel.com/docs/5.4/mix#copying-files-and-directories