Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission denied on mkdir()

I'm getting the following error when trying to call mkdir() on a server...

Warning: mkdir() [function.mkdir]: Permission denied in /home/server/public_html/wp-content/themes/mytheme/catimages/cat-images.php on line 373

The function is below. Its attempting to create a folder under the site's "wp-content/uploads folder". I've verified that the PHP Version is 5.2.15 and that the files inside the theme folder are writable, but that does not necessarily means the uploads folder is writable I suppose.

How can I find out if the uploads folder is writable?

protected function category_images_base_dir()
{
    // Where should the dir be? Get the base WP uploads dir
    $wp_upload_dir = wp_upload_dir();
    $base_dir = $wp_upload_dir[ 'basedir' ];
    // Append our subdir
    $dir = $base_dir . '/cat-images';
    // Does the dir exist? (If not, then make it)
    if ( ! file_exists( $dir ) ) {
        mkdir( $dir ); //THIS IS LINE 373
    }
    // Now return it
    return $dir;
}
like image 526
Scott B Avatar asked Feb 10 '11 20:02

Scott B


2 Answers

is_writable() is probably the function you're looking for.

http://cz.php.net/manual/en/function.is-writable.php says:

Returns TRUE if the filename exists and is writable. The filename argument may be a directory name allowing you to check if a directory is writable.

Also, the directly next line is relevant here:

Keep in mind that PHP may be accessing the file as the user id that the web server runs as (often 'nobody').

In other words, check if your directory is writable by the user id of the web server - this may be a different user id than yours! Set the appropriate permissions - e.g. set the usergroup of the folder to that of the server's user, and grant read, write, and execute to group. (chgrp somegroup uploads; chmod g+r uploads; chmod g+w uploads; chmod g+x uploads)

like image 171
Piskvor left the building Avatar answered Oct 02 '22 23:10

Piskvor left the building


Make sure the parent folder is writable to the process that the web server runs as.

Edit: Oops, premature reply. Does your host give you a GUI file browser thingy?

like image 29
Alex Howansky Avatar answered Oct 02 '22 21:10

Alex Howansky