Search code examples
phppermissionsmkdir

PHP mkdir returns false but exec("mkdir") works


I need to create a folder in PHP outside the web root.

The parent folder has 777 permissions.

If I call mkdir($dir); or mkdir($dir, 0777, true); it returns false and the folder isn't created.

However, if I call exec("mkdir ".$dir); the folder is created.

Is it normal?


Solution

  • Older versions of php had different parameters for mkdir.

    Try mkdir($dir, permissions);

    Example:

    mkdir($dir, 0777);
    

    But I recommend updating the version of php