note 40292 added to function.mkdir

From: Date: Fri, 27 Feb 2004 16:17:27 +0000
Subject: note 40292 added to function.mkdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-65895@lists.php.net to get a copy of this message
I modified Shaun's version of mkdir_p slightly. 1) I consider an existing directory a success, not a failure 2) If the file exists and is not a directory, then we have a possible issue and the function returns 0 3) I changed 'eregi' to 'ereg' 4) I simplified the recursive call, eliminating the if statements function mkdir_p($target) { if (file_exists($target) && !is_dir($target)) return 0; // failure if (substr($target, 0, 1) != '/') $target = "/".$target; // prepend a slash if (ereg('\.\.', $target) || ereg("[^a-zA-Z0-9\._\-\/]", $target)) return 0; // if illegal dirname if (mkdir($target)) // if new dir created, return 1; // we are successful if (mkdir_p(substr($target, 0, (strrpos($target, '/')))) == 1) return (mkdir_p($target)); else return 0; } ---- Manual Page -- http://www.php.net/manual/en/function.mkdir.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40292 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40292&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40292&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#65895) next »