PHP mkdir( $recursive = true ) skips last directory

后端 未结 7 1936
南旧
南旧 2021-02-20 10:39

I\'ve got the following piece of code on a PHP 5.2.4 (no safe_mode) linux server:

mkdir( $path, 0777, true );

when I enter a path like:

<
7条回答
  •  感情败类
    2021-02-20 10:58

    Function that create all directories (folders) of given path. No need to write code create each directories (folders) of given path. it will create all directories (folders).

    Like : If you want to create directory structure like
    organizations / 1 / users / 1 /

    So you only need to call this function with directories path like
    $directories_path = 'organizations/1/users/1/';
    createUploadDirectories($directories_path);

    /*
    * Method Name : createUploadDirectories
    * Parameter : null
    * Task : Loading view for create directries for upload
    */
    
    if ( ! function_exists('createUploadDirectories')){
        function createUploadDirectories($upload_path=null){
            if($upload_path==null) return false;
            $upload_directories = explode('/',$upload_path);
            $createDirectory = array();
            foreach ($upload_directories as $upload_directory){
                $createDirectory[] = $upload_directory;
                $createDirectoryPath = implode('/',$createDirectory);
                if(!is_dir($createDirectoryPath)){
                    $old = umask(0); 
                    mkdir($createDirectoryPath,DIR_WRITE_MODE);// Create the folde if not exist and give permission
                    umask($old); 
                }               
            }
            return true;
        }
    }
    

提交回复
热议问题