Create file and folders recursively

前端 未结 3 798
轻奢々
轻奢々 2021-01-11 14:03

I got an array containing path names and file names

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

I want to create

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-11 15:00

    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 file permission expression, you can read about it here: http://ch.php.net/manual/en/function.chmod.php

提交回复
热议问题