Results 1 to 9 of 9

Thread: mkdir() call in a theme?

  1. #1
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,797

    Default mkdir() call in a theme?

    A friend of mine showed me a site of his which is spitting out the following message on updating options in the theme options page after upgrading his theme to the latest version:
    Code:
    Warning: mkdir() [function.mkdir]: Permission denied
    He needed to upgrade the theme because the original was no longer working with the current version of WordPress. But why on earth would a theme need to use mkdir()? The error seems to be related to a line which is trying to create a directory with file permissions of 777. I can't see why a theme would need to create a directory let alone require it to have file permissions of 777.


    The theme was OpenAir by Woo Themes.
    Has anyone else had this problem with Woo Themes themes before? Any ideas on how to get around it?

  2. #2
    Len's Avatar
    Len
    Len is offline Big Tipper
    Join Date
    Jan 2009
    Location
    Winnipeg, MB Canada
    Posts
    376

    Default

    Is the theme using some sort of auto image resizer script that stores images in a cache folder it created? Cache folder having permissions of 777? Dunno, just a thought.

  3. #3
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,797

    Default

    Hmm, maybe it's a thumbnail'ing system perhaps. Although I'd have thought the regular uploads directory would be a much smarter place to store anything like that rather than the theme folder itself.

  4. #4
    ledfrog is offline Hello World
    Join Date
    Feb 2010
    Posts
    1

    Default

    I'm not sure if you ever solved this or not, but in case you didn't or someone else needs the help, here's all you need to do.

    The rest of that error should tell you what file and what line of code is giving you the problem. If you look in the file on that line, you'll find the code that says something about "mkdir" and they'll be a direction name that it's trying to make.

    Just navigate to the location of that directory on your server and give write permissions to the folder. Problem solved.

  5. #5
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,797

    Default

    That may solve the problem, but it doesn't explain why it would need to write to the server.

  6. #6
    Otto's Avatar
    Otto is offline On The Rocks
    Join Date
    Apr 2009
    Location
    Memphis, TN
    Posts
    862

    Default

    Without actually seeing the code, it's difficult to say why it would be trying to do that.

    As a matter of good WordPress coding practice, plugins and themes should never create any files/folders outside of the uploads folder. Nowhere else is guaranteed to have permissions set so that you can write there.

  7. #7
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,797

    Default

    Quote Originally Posted by Otto View Post
    As a matter of good WordPress coding practice, plugins and themes should never create any files/folders outside of the uploads folder.
    Is there any procedure on how/where to do that?

    It seems odd to just dump files randomly into the folder, but if that's the way to do it then that's what I'll do!

  8. #8
    Otto's Avatar
    Otto is offline On The Rocks
    Join Date
    Apr 2009
    Location
    Memphis, TN
    Posts
    862

    Default

    Quote Originally Posted by Ryan View Post
    Is there any procedure on how/where to do that?

    It seems odd to just dump files randomly into the folder, but if that's the way to do it then that's what I'll do!
    First you call wp_upload_dir, to get the upload directory. This actually returns an array with several possible directories to choose from.

    From here, you have several choices, depending on what you're doing. You pick one of the directories from the array, and you can even add yourself a subdirectory name onto it, if you like.

    Next you would call wp_unique_filename($dir, $filename), in order to obtain a filename that doesn't conflict with any existing names there.

    Once you have those, you just use normal PHP file functions to create and write whatever you like to the file.

    If you want to use uploading from the browser, then there's a lot of functions to handle that in WordPress without doing the above. wp_handle_upload() is the big one that does all the work.

    If you want to create a new file and don't really care where it goes, look at wp_upload_bits().

  9. #9
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,797

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •