Mkdir With Error Checking

Description: A mkdir function with a simple exception handler.

<?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;
 
}
 
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.