note 81119 deleted from function.mkdir by crell

From: Date: Wed, 29 Jun 2022 19:10:53 +0000
Subject: note 81119 deleted from function.mkdir by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218700@lists.php.net to get a copy of this message
Note Submitter: code at ashleyhunt dot co dot uk ---- Here's a script to create a recursive directory path on NAS or another server using Common Internet File System (CIFS) e.g. you already have a directory on a server \\server/share/dir1/dir2 you want to create some more directories \\server/share/dir1/dir2/dir3/dir4 <?php function remote_mkpath($server, $path) { $dirs = array(); $path = preg_replace('/(\/){2,}|(\\\){1,}/','/',$path); //only forward-slash $dirs = explode("/", $path); $path = "\\\\" . $server . "/"; $i = 0; foreach ($dirs AS $element) { $path .= $element . "/"; if(!is_dir($path) && $i != 0) { if(!mkdir($path)){ echo "something was wrong at : " . $path; return 0; } } $i++; } return true; echo $path; } // example usage remote_mkpath("SERVER", "share/dir1/dir2/dir3/dir4"); ?> Good luck! Ashley

« previous php.notes (#218700) next »