You can try this:
if (! file_exists('path/to/directory')) {
mkdir('path/to/directory', 0777, true);
}
First, check if the directory exists with the function file_exists()
. Then use mkdir()
to create the directory with 0777 or required directory permission.