Zend - The PHP Company




Files and Directories

Add Code


Create Path  

Type: code fragment
Added by: jijutm
Entered: 01/11/2006
Last modified: 02/11/2005
Rating: - (fewer than 3 votes)
Views: 2460
Creates deep directory structrure path to any depths.


<?php
/**
 * Creating directories recursively
 *
 * @param string $dirName
 * @param octal $rights, see chmod manual
 * for more see http://www.phptrivandrum.org
 */

function mkdir_r($dirName$rights=0777){
   
$dirs explode('/'$dirName);
   
$dir='';
   foreach (
$dirs as $part) {
       
$dir.=$part.'/';
       if (!
is_dir($dir) && strlen($dir)>0)
           
mkdir($dir$rights);
   }
}

?>


Usage Example


mkdir_r($_SERVER['DOCUMENT_ROOT'] . '/downloads/1/2/3');

will create 1/2/3 in downloads.


Rate This Script





Search



This Category All Categories