note 42150 added to function.mkdir

From: Date: Wed, 05 May 2004 12:46:26 +0000
Subject: note 42150 added to function.mkdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-69229@lists.php.net to get a copy of this message
Let's have some remarks, the second regular expression given in the example below crashed when you got - in names. I fixed it. Moreover, I have considered here that when the directory is alreaded created, this is considered as success and nothing need to be done. I don't like either to let structures without delimiters, taking account explains are your ONLY FRIENDS when something WRONG HAPPENS.Notice this mkdir_p will not work properly with windows pathnames (containing \ as usual). function mkdir_p($target){ //------------------------ if (file_exists($target) && !is_dir($target)) { //echo "Failure, the directoy name conflicts with an existing filename "; return 0; } if (substr($target, 0, 1) != '/') { $target = "/".$target; // prepend a slash } if (ereg('\.\.', $target) || ereg("[a-zA-Z0-9]+[\.\-\/]*", $target)) { //echo "illegal dirname".htmlspecialchars($target); return 0; } if (is_dir($target) || @mkdir($target)) { // if new dir created or directory already created return 1; // we are successful } else { //echo "mkdir unsuccesfull , trying further with recursivity"; } if (mkdir_p(substr($target, 0, (strrpos($target, '/')))) == 1) { return (mkdir_p($target)); } else { //echo "mkdir_p failure, please check you rights for the directory ".htmlspecialchars($target) ; return 0; } } ---- Manual Page -- http://www.php.net/manual/en/function.mkdir.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42150 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42150&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42150&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69229) next »