Laravel, unable to copyDirectory or moveDirectory

前端 未结 2 711
不知归路
不知归路 2021-01-16 12:33

Currently I having problem with Laravel cannot use moveDirectory and copyDirectory however makeDirectory or deleteDirectory works fine, the code as follow:

&         


        
相关标签:
2条回答
  • 2021-01-16 13:27

    Use the File::copyDirectory() method.

    $success = File::copyDirectory($sourceDir, $destinationDir);

    The method will return true if all files and subdirectories are successfully copied.

    If the destination directory doesn't exist it will be created. It will be created recursively as needed.

    0 讨论(0)
  • 2021-01-16 13:30

    I guess moveDirectory is not available under Storage. Try with below code

    import file system first

    use Illuminate\Filesystem\Filesystem;
    

    after that create a new instance and move directory. Path is relative to index.php I guess.

    $file = new Filesystem();
    $file->moveDirectory('../storage/app/public/old_folder', '../storage/app/public/new_folder');
    

    Edited

    You can bypass instance creation with method injection

    public function update(Request $request,Filesystem $file, $id)
    
    0 讨论(0)
提交回复
热议问题