PDA

View Full Version : PHP5 and mkdir() recursive



Bl4deRunner
30th June 2006, 09:59 PM
Using PHP5, the EASIEST way to create all the recursive directories with one command, using the mkdir() function, with the 'recursive' parameter set to 'true'
<?php
$saveLocation= "/testdir/test1/test2/test4";
mkdir($saveLocation,0666,true);
?>

For me, however, it didn't work, using FEDORA CORE 5.
After days of wondering and testing, I found the soultion in using umask.
(More information can be found here:
http://www.php.net/umask
and here
http://en.wikipedia.org/wiki/Umask)

This works:
<?php
$saveLocation= "/testdir/test1/test2/test4";
if (!is_dir($saveLocation)){
$oldumask = umask(0);
mkdir($saveLocation,0666,true);
umask($oldumask);
}
?>

I have no clue if there are any security-risks involved in this solution though... (I'm hoping that someone can tell?)