angry_kiwi angry_kiwi - 2 years ago 99
PHP Question

Create file and folders recursively

I got an array containing path names and file names

['css/demo/main.css', 'home.css', 'admin/main.css','account']

I want to create those files and folders if they are not existed yet. Overwrite them if they are already existed.

Answer Source

For each of this paths you'll have to specific whether it is a file or a directory. Or you could make your script assume, that the path is pointing to a file when the basename (the last part of the path) contains a dot.

To create a directory recursively is simple:

mkdir(dirname($path), 0755, true); // $path is a file
mkdir($path, 0755, true);          // $path is a directory

0755 is the umask, you can read about it here:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download