Hello,

Sign up to join our community!

Welcome Back,

Please sign in to your account!

Forgot Password,

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

BashCow Latest Questions

  • 44
  • 44
rylan98

Create a folder if it doesn't already exist

I’ve encountered situations with WordPress installations on hosting where errors occurred due to the missing wp-content/uploads directory.

It appears that the hosting cPanel WordPress installer does not create this folder by default, whereas the installer from HostGator does.

Therefore, I need to add code to my theme to check for the existence of this folder and create it if it’s missing.

Related Questions

2 Answers

  1. In new update it works by default. No changes are required.

    In new update it works by default.

    No changes are required.

    See less
  2. Here is the simple method to make the directory if its not created. /** * recursively create a long directory path */ function createPath($path) { if (is_dir($path)) return true; $prev_path = substr($path, 0, strrpos($path, '/', -2) + 1 ); $return = createPath($prev_path); return ($return && is_writable($prev_path)) ? mkdir($path) : false; }

    Here is the simple method to make the directory if its not created.

    /**
     * recursively create a long directory path
     */
    function createPath($path) {
        if (is_dir($path)) 
            return true;
        $prev_path = substr($path, 0, strrpos($path, '/', -2) + 1 );
        $return = createPath($prev_path);
        return ($return && is_writable($prev_path)) ? mkdir($path) : false;
    }
    See less
Leave an answer

Leave an answer