note 44654 deleted from function.mkdir by aidan

From: Date: Sun, 03 Oct 2004 13:35:13 +0000
Subject: note 44654 deleted from function.mkdir by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-77825@lists.php.net to get a copy of this message
Note Submitter: bart at cdasites dot com ---- The mkdir_p function submitted by saint at corenova.com is nice and simple, but errors when trying to create several directories in a tree, eg: /foo/bar/baz/1 /foo/bar/baz/2 /foo/bar/baz/3 Adding a check before the mkdir function fixes this. // Amended Function: function mkdir_p($target) { if (is_dir($target)||empty($target)) return 1; // best case check first if (file_exists($target) && !is_dir($target)) return 0; if (mkdir_p(substr($target,0,strrpos($target,'/')))) if (!file_exists($target)) return mkdir($target); // crawl back up & create dir tree return 0; } Thx for the function Saint, made my life easier :)

« previous php.notes (#77825) next »