Scott B Scott B - 5 months ago 12x
PHP Question

Create a folder if it doesn't already exist

I've run into a few cases with WordPress installs with Bluehost where I've encountered errors with my WordPress theme because the uploads folder

was not present.

Apparently the Bluehost cPanel WP installer does not create this folder, though HostGator does.

So I need to add code to my theme that checks for the folder and creates it otherwise.


Try this:

if (!file_exists('path/to/directory')) {
    mkdir('path/to/directory', 0777, true);

Note that 0777 is already the default mode for directories and may still be modified by the current umask.