如何在PHP中创建一个文件夹?

Now in my code one folder is createed like private/119 when I logged into my application. The code is,

if (!is_dir('private/'.$q->row()->userId)) {
    $oldmask = umask(0);
    $q=mkdir('private/' .$q->row()->userId,0777,true);
    umask($oldmask);
    copy('public/images/default_user.png','private/'.$q->row()->userId.'/default-profile_pic.png');
}

Now I want to create a one more folder inside that userId(119) folder. How to do that? I have tried something like that $q=mkdir('private/' .$q->row()->userId .'/beforeconvert',0777,true); but it is not working.

Or is the following code is correct?

if (!is_dir('private/'.$q->row()->userId) && !is_dir('private/'.$q->row()->userId .'/beforeconvert')) {
    $oldmask = umask(0);
    $q=mkdir('private/' .$q->row()->userId,0777,true);
    $create_folder = mkdir('private/' .$q->row()->userId .'/beforeconvert',0777,TRUE);
    umask($oldmask);
    copy('public/images/default_user.png','private/'.$q->row()->userId.'/default-profile_pic.png');
}

According to your code direcoty beforeconvert will not created if parent directory : $q->row()->userId already exist.

Also you don't need to create first parent directory then child. You can directly create child directory with mkdir it will create parent directory also.

Change your code as below:

<?php
if (!is_dir('private/'.$q->row()->userId .'/beforeconvert')) {
    $oldmask = umask(0);    
    $create_folder = mkdir('private/' .$q->row()->userId .'/beforeconvert',0777,TRUE);
    umask($oldmask);
    copy('public/images/default_user.png','private/'.$q->row()->userId.'/default-profile_pic.png');
}