如何使用 laravel 5 从一个文件夹复制整个目录到另一个文件夹

How copy entire directory from one folder two another using laravel 5

可能是因为它太简单了,但我在 google 或这里找不到任何合适的答案!!

我用过

\File::copyDirectory('public/' . $token . '/cover/', $folderName . '/cover/');

但没有什么不同!!

This is where I found above solution.

您知道如何使用 laravel 5.4 将整个目录从一个文件夹复制到另一个文件夹吗?

提前致谢

尝试使用 mix.copy() 方法。

mix.copy('public/' . $token . '/cover/', $folderName . '/cover/');

阅读更多信息:https://laravel.com/docs/5.4/mix#copying-files-and-directories

一年多后:)

使用路径辅助函数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));

我使用了 Storage facades 并且效果很好

config/filesystems.php

'disks' => [
    'local' => [
        'driver' => 'local',
        'root' => public_path(),
    ],
     ...
]

将所有文件从 public/seed_images/ 复制到 public/images/

app/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 );
}