Support » Plugins » Hacks » mkdir function not working

  • Resolved yeagerc50


    This works fine when testing it on a page with a custom template:

    add_action (‘folder’, function(){
    $tempDir = realpath(‘wp-content/themes’);
    $tempDir = $tempDir.”\used-car-lot-theme”;

    but when I move it to the register_activation_hook function in my plugin it pukes with this error:
    Warning: mkdir() [function.mkdir]: File exists
    and the folder is not created. (and no, the file does not exist).

    Help please 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • Have you checked what $tempDir (e.g. with var_dump) “really” contains when calling it via the register activation hook?
    Maybe using ABSPATH instead of realpath() does a better job?

    $tempDir = ABSPATH . DIRECTORY_SEPARATOR . 'wp-content' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . 'used-car-lot-theme';

    Yes, actually I did check it.
    My version produces:

    Your version produces:

    I removed the first DIRECTORY_SEPARATOR from your line and got:

    And it worked!
    Apparently, the path TO and FROM the working directory needs to be there to create the directory.

    Now all I need to do is handle the “File Exists” notice.
    while I’m working on it ……… Any suggestions are welcome.

    Thank You Chris.

    The @ symbol suppresses the notice. @mkdir()

    Right. And you could still handle errors based on error_get_last()

    if( !file_exists( $tempDir ) && !@mkdir( $tempDir ) ) {
      $error = error_get_last();
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘mkdir function not working’ is closed to new replies.