Constantin.FF
Constantin.FF

Reputation: 697

CakePHP copy file to new directory

The cakephp documentation is a bit poor according the File api and I would like to use it to copy one file to another directory and if the directory does not exist to create it.

Thanks!

Upvotes: 4

Views: 7651

Answers (1)

Paulo Rodrigues
Paulo Rodrigues

Reputation: 5303

You can do something like this:

$file = new File('your_file.ext');

if ($file->exists()) {
    $dir = new Folder('folder_inside_webroot', true);
    $file->copy($dir->path . DS . $file->name);
}

API about these classes:

I hope it helps.

Upvotes: 9

Related Questions