0

所以正如标题所说,我正在努力将一个文件夹复制到另一个文件夹

我试过这个但没有结果

编辑:我通过修复 $npath 变量来实现这一点,我只是给出了没有文件夹名称的 url$npath = $newk->url;

所以最终的代码将是:

    public function copyFolder(Request $request)
{
    $id= $request->get('oldf');
    $new = $request->get('newf');

    $document = Document::find($id);
    $newk = Document::find($new);

    $npath = $newk->url.'/'.$document->nom;

    $file= new Filesystem();

    if($file->copyDirectory($document->url, $npath)){
        return redirect('home');
    }
    return redirect('home');

}

任何帮助,将不胜感激 :)

4

1 回答 1

0

使用这个功能

function recursive_files_copy($source_dir, $destination_dir)
{
    // Open the source folder / directory 
    $dir = opendir($source_dir);

    // Create a destination folder / directory if not exist 
    if (!is_dir($destination_dir)){
        mkdir($destination_dir);
    }
    // Loop through the files in source directory 
    while($file = readdir($dir))
    {
        // Skip . and .. 
        if(($file != '.') && ($file != '..'))
        {
            // Check if it's folder / directory or file 
            if(is_dir($source_dir.'/'.$file))
            {
                // Recursively calling this function for sub directory  
                recursive_files_copy($source_dir.'/'.$file, $destination_dir.'/'.$file);
            }
            else
            {
                // Copying the files
                copy($source_dir.'/'.$file, $destination_dir.'/'.$file);
            }
        }
    }
    
    closedir($dir);
}
于 2020-12-28T13:56:27.050 回答