Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




wp_mkdir_p [ WordPress Function ]

wp_mkdir_p ( $target )
Parameters:
  • (string) $target Full path to attempt to create.
Returns:
  • (bool) Whether the path was created. True if path already exists.
Defined at:



Recursive directory creation based on full path.

Will attempt to set permissions on folders.

Source


<?php
function wp_mkdir_p$target ) {
    
// from php.net/mkdir user contributed notes
    
$target str_replace'//''/'$target );

    
// safe mode fails with a trailing slash under certain PHP versions.
    
$target rtrim($target'/'); // Use rtrim() instead of untrailingslashit to avoid formatting.php dependency.
    
if ( empty($target) )
        
$target '/';

    if ( 
file_exists$target ) )
        return @
is_dir$target );

    
// Attempting to create the directory may clutter up our display.
    
if ( @mkdir$target ) ) {
        
$stat = @statdirname$target ) );
        
$dir_perms $stat['mode'] & 0007777;  // Get the permission bits.
        
@chmod$target$dir_perms );
        return 
true;
    } elseif ( 
is_dirdirname$target ) ) ) {
            return 
false;
    }

    
// If the above failed, attempt to create the parent node, then try again.
    
if ( ( $target != '/' ) && ( wp_mkdir_pdirname$target ) ) ) )
        return 
wp_mkdir_p$target );

    return 
false;
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

Gebruikersdiscussies [ wordpress.org ]

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics