What is the right way to create a folder?

Hi,

I would like to create an order using CakePHP 4. However, according to the documentation https://book.cakephp.org/4/en/core-libraries/file-folder.html#folder-api the class is deprecated and will be removed soon. Now the question arises which API I should use now.

Is this the right way?

$directory = APP . 'DATA' . DS . 'Images' . DS;
if (!is_dir($directory)) {
 mkdir($directory, 0777, true);
}

Using vanilla PHP is perfectly fine, that’s what the deprecation notice in the docs is is meant to suggest. If you want to use a library, check symfony/filesystem and symfony/finder.

1 Like