0

我想将目录复制或移动到 laravel 中的新目录,但 copyDirectory 函数总是向我返回 false。我的代码有什么问题吗?提前致谢

$destinationDir = 'storage/Components/'.'Compressor'.'/'.$approvedRequest['compressor_model'].'/';
$success = File::copyDirectory(public_path().$approvedRequest['attachment_dir'], public_path().$destinationDir,true);
$compressorUpdate->attachment_dir = $destinationDir;
4

2 回答 2

0

我认为您正在尝试复制到符号链接目录。您应该参考目录的真实路径而不是其符号链接。所以storage_path()改用。

$destinationDir = implode(DIRECTORY_SEPARATOR, ['Components', 'Compressor', $approvedRequest['compressor_model']]);
        $success = \File::copyDirectory(
            public_path() . $approvedRequest['attachment_dir'],
            storage_path() . DIRECTORY_SEPARATOR . $destinationDir, true);
        $compressorUpdate->attachment_dir = $destinationDir;
于 2021-07-15T14:53:52.560 回答
0

我相信当前目录在

storage/Components/Compressor/{$approvedRequest['compressor_model']}/

并想复制到

public/storage/Components/Compressor/{$approvedRequest['compressor_model']}/

所以你可以简化

$path="Components/Compressor/{$approvedRequest['compressor_model']}/";

$currentDirectory=storage_path($path);
$destinationDir =public_path($path);

$success = File::copyDirectory($currentDirectory,$destinationDir);
于 2021-07-15T14:52:13.640 回答