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

问题描述 投票:0回答:6

可能很简单,但我在谷歌或这里找不到任何正确的答案!!

我确实用过

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

但是没有什么不同!!

这是我找到上述解决方案的地方。

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

提前致谢

laravel laravel-5 copy
6个回答
15
投票

一年多过去了:)

使用路径助手函数https://laravel.com/docs/5.6/helpers

\File::copyDirectory( public_path . 'to/the/app', resource_path('to/the/app'));

8
投票

我们可以在 Laravel 5.8 中使用文件门面来做到这一点,如下所示:

use Illuminate\Support\Facades\File;  

File::copyDirectory(__DIR__.'/form-directory', resource_path('to-directory'));

希望,这会有所帮助。


1
投票

就这样做:

   /* Move test images from public folder to storage folder */
    $source = "source/path";
    $destination = "public/files";

    File::copyDirectory(base_path($source), base_path($destination));

0
投票

我使用了存储立面并且效果很好

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

0
投票
/**
 * 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'
);

-3
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.