0

I'm relatively new to PHP and I'm trying to write my own plugin. Upon plugin activation it will run the following function:

function kb_create_uploadfolder () {
     global $wpdp;

     $upload_dir = wp_upload_dir();
     $upload_dir = $upload_dir['basedir'] . "/plugin_uploads";
     $upload_dircheck = wp_mkdir_p($upload_dir);    
}

I didn't bother to check whether the directory already exists before creating it since I figured it won't overwrite anything or delete the contents if it does. Correct me if I'm wrong.

The thing is however, I would like to check if the creation of the directory was succesful or not but I can't figure out how to get this information.

3 Answers 3

2

Use is_dir():

if(is_dir($upload_dircheck))
{
    echo "It is a dir";
}
else
{
    echo "Sorry, non-existent or not a dir";
}

Also, mkdir() doesn't delete or overwrite existing contents, it just creates a directory if it does not yet exist.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for verifying my earlier thoughts about mkdir()!
1

If you're using PHP 4 or newer then you can use the is_dir() function.

Comments

1

Try is_dir().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.