php mkdir仅在777文件夹中创建文件夹时才有效

I have a folder called 'folders'. I want to create a folder inside 'folders' called 'folder' with mkdir()

However the folder fails to create when 'folders' is set to 755. The only may I can get mkdir to work is making 'folders' 777. Is this typical or is there something else wrong? Shouldn't be able to do that on 755, isn't 777 a security risk?

A 777 permission on the directory means that everyone has access to read/write/execute (execute on a directory means that you can do a ls of the directory).

Try this one below if you fails to create folder inside the folder.

   <?php
    // Desired folder structure
    $structure = './folders/folder/';

    // To create the nested structure, the $recursive parameter 
    // to mkdir() must be specified.

    if (!mkdir($structure, 0755, true)) {
        die('Failed to create folders...');
    }
    ?>