Quick Search:
 
 PHP Code: MKDIR with error checking Jump to:  
Category: >> PHP Code >> MKDIR with error checking  

<< lastnext >>

Snippet Name: MKDIR with error checking

Description: A mkdir function with a simple exception handler.

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 11th, 2009

<?PHP
 
FUNCTION handleError() {
    TRIGGER_ERROR('MY ERROR');
 
    /** usage sample
        @handleError();
        echo $php_errormsg;
    */
}
 
// detect slash/backslash nomenclature dirname
$path = DIRNAME( __FILE__ );
$slash = '/'; STRPOS( $path, $slash ) ? '' : $slash = '\\';
DEFINE( 'BASE_DIR', $path . $slash );
 
$folder  = TIME();               // folder name
$dirPath = BASE_DIR . $folder;   // folder path
 
// print results
ECHO $slash;
ECHO '<hr>';
 
$rs = @MKDIR( $dirPath, '0777' );
@handleError();
IF( $rs )
{
 
    // print success information
    ECHO 'was done!';
    ECHO '<br>folder: <a href="' . $folder . '">' . $folder . '</a>';
    ECHO '<br>dirPath: ' . $dirPath;
 
}ELSE{
 
    // print error information
    ECHO 'an error was occurred. Attempting create folder';
    ECHO '<br>dirPath: ' . $dirPath;
    ECHO '<br>php_errormsg: ' . $php_errormsg;
 
}
 
?>


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org