PHP Doku:: Erstellt ein Verzeichnis - function.mkdir.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDateisystemrelevante ErweiterungenDateisystemDateisystem-Funktionenmkdir

Ein Service von Reinhard Neidl - Webprogrammierung.

Dateisystem-Funktionen

<<lstat

move_uploaded_file>>

mkdir

(PHP 4, PHP 5)

mkdirErstellt ein Verzeichnis

Beschreibung

bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )

Versucht ein Verzeichnis mit dem angegebenen Namen zu erstellen.

Parameter-Liste

pathname

Der Verzeichnispfad.

mode

Der Modus ist standardmäßig 0777, was den größtmöglichen Zugang umfasst. Für weitere Informationen lesen Sie bitte die Details auf der chmod()-Seite.

Hinweis:

mode wird unter Windows ignoriert.

Beachten Sie, dass Sie den Modus als oktalen Wert angeben sollten, d.h., dass er eine führende Null haben sollte. Der Modus wird auch durch die aktuelle umask geändert, die Sie mit umask() ändern können.

recursive

Erlaubt die Erstellung von im pathname angegebenen verschachtelten Verzeichnissen. Standardmäßig FALSE.

context

Hinweis: Die Kontext-Unterstützung gibt es seit PHP 5.0.0. Eine Beschreibung von Kontexten finden Sie unter Stream Funktionen.

Rückgabewerte

Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben.

Changelog

Version Beschreibung
5.0.0 Der recursive-Parameter wurde hinzugefügt.
5.0.0 Seit PHP 5.0.0 kann mkdir() auch mit einigen URL-Wrappern genutzt werden. In der Supported Protocols and Wrappers finden Sie eine Liste aller Wrapper, die mkdir() unterstützen.
4.2.0 Der mode-Parameter wurde optional.

Beispiele

Beispiel #1 mkdir()-Beispiel

<?php
mkdir
("/path/to/my/dir"0700);
?>

Beispiel #2 mkdir() mit dem recursive-Parameter benutzen

<?php
// Gewünschte Verzeichnisstruktur
$structure './stufe1/stufe2/stufe3/';

// Zur Erstellung der verschachtelten Struktur muss der $recursive-Parameter 
// von mkdir() angegeben werden

if (!mkdir($structure0true)) {
    die(
'Erstellung der Verzeichnisse schlug fehl...');
}

// ...
?>

Anmerkungen

Hinweis: Wenn Safe Mode aktiviert ist überprüft PHP, ob das Arbeitsverzeichnis, die gleiche UID (Eigentümer) hat wie das Skript selbst.

Siehe auch

  • is_dir() - Prüft, ob der angegebene Dateiname ein Verzeichnis ist
  • rmdir() - Löscht ein Verzeichnis


39 BenutzerBeiträge:
- Beiträge aktualisieren...
Benjamin Rack
2.12.2010 13:18
It should be mentioned that - at least on Windows - when using UNC paths with mkdir the 2nd parameter $mode should not be specified. Otherwise mkdir fails to create the directory on the given UNC path.
Anonymous
25.09.2010 16:18
The mode on your directory is affected by your current umask.  It will end
up having (<mkdir-mode> and (not <umask>)).  If you want to create one
that is publicly readable, do something like this:

<?php
$oldumask
= umask(0);
mkdir('mydir', 0777); // or even 01777 so you get the sticky bit set
umask($oldumask);
?>

____________
http://kuritelnye-smesi.od.ua
satis at clankiller dot com
8.09.2010 15:05
Please note that in a shared environment I failed to take into account an existing umask when I did a mkdir(dirname, 0755).  This ended up creating the directory (function returned true), but I didn't have rights to do anything inside the folder, nor could I even view that it existed via ftp.

However, file_exists(dirname) returned true.  Eventually I figured out what happened and was able to rmdir(dirname), then created the directory correctly.

So, when writing scripts you expect to be portable, either use umask to set your umask accordingly, or do a straight mkdir(dirname) followed by chmod(dirname, 0755) (or whatever it is you're looking for).  If you make the same mistake I did, you should be able to rmdir() or chmod() the folder so it's accessible.
vishal at e-arth dot in
27.08.2010 9:59
I used the following syntax to create directory

mkdir('mydir', 0777);

directory get created but it's permissions not set to 777, that is why I am not able to upload the images in this folder.
my server is linux
any solutions??
jack dot sleight at gmail dot com
26.03.2010 12:26
When using the recursive parameter bear in mind that if you're using chmod() after mkdir() to set the mode without it being modified by the value of uchar() you need to call chmod() on all created directories. ie:

<?php
mkdir
('/test1/test2', 0777, true);
chmod('/test1/test2', 0777);
?>

May result in "/test1/test2" having a mode of 0777 but "/test1" still having a mode of 0755 from the mkdir() call. You'd need to do:

<?php
mkdir
('/test1/test2', 0777, true);
chmod('/test1', 0777);
chmod('/test1/test2', 0777);
?>
michael at neo dot co dot il
27.01.2010 16:39
sometimes the directory created with another mode than specified ( 0755 instead 0777  etc).
to solve that use :

<?php
$old
= umask(0);
mkdir($dir,0777);
umask($old);
?>
Brian S
11.08.2009 17:51
The example from "hinom - iMasters" below is broken -- here's a version that works:

<?php

function handleError() {
   
trigger_error('MY ERROR');

   
/** usage sample
        @handleError();
        echo $php_errormsg;
    */
}

// detect slash/backslash nomenclature dirname
$path = dirname( __FILE__ );
$slash = '/';

(
stristr( $path, $slash )) ? '' : $slash = '\\';
define( 'BASE_DIR', $path . $slash );

$folder  = time();               // folder name
$dirPath = BASE_DIR . $folder;   // folder path

// print results
echo $slash;
echo
'<hr>';

$rs = @mkdir( $dirPath, 0777 );
@
handleError();
if(
$rs )
{

   
// print success information
   
echo 'was done!';
    echo
'<br>folder: <a href="' . $folder . '">' . $folder . '</a>';
    echo
'<br>dirPath: ' . $dirPath;

}else{
  
   
// print error information
   
echo 'an error was occurred. Attempting create folder';
    echo
'<br>dirPath: ' . $dirPath;
    echo
'<br>php_errormsg: ' . $php_errormsg;

}

?>

[EDIT by thiago AT php DOT net: This function has a fix from imran@curl.phptrack.com]
ethaizone at hotmail dot com
3.08.2009 22:10
When I created folder on windows with mkdir, I found some problem from folder nam so I write this function.

<?php
function filename_safe($name) {
   
$except = array('\\', '/', ':', '*', '?', '"', '<', '>', '|');
    return
str_replace($except, '', $name);
}
?>

It can use with another functions about file system as file_put_contents to clean up file name.
vlad at todosv dot com
5.03.2009 17:59
Note that you should NOT enter the $mode value with "" or '' sorrounding it.

So, this should be valid:
<?php mkdir("dir1/dir2",0777,true); ?>

But this is not:
<?php mkdir("dir1/dir2","0777",true); ?>

Nor this:
<?php mkdir("dir1/dir2",'0777',true); ?>
d dot kok at kadova dot nl
20.02.2009 9:02
Please note that when specifying the recursive option the function returns false anyway if the directory already exists.

For some reason however I expected it to behave like `mkdir -p` on the command line which succeeds if the directory already exists.
t-k-r at o2 dot pl
17.12.2008 10:42
Very simple script, may be useful to someone.
Creating a directory structure liki this:

0 ------ 0
1          1
2          2 -------- 0
3          3             1
4          ...           2
5                        3
6                        ...
7
[....]
e
f

Used by my as structure to store uploaded files:
someone upload file -> its name + microtime is md5 -> first 3 letters of md5 string are first 3 subfolders in this folder structure, and at least file is stroed with md5 name.
Naturally SQL- or other type - Database is needed to store infos about files position in this structure.

<?php

for ($a=0;$a<=15;$a++) {
   
   
mkdir(dechex($a),0755);

    for (
$b=0;$b<=15;$b++) {

       
mkdir(dechex($a).'/'.dechex($b),0755);

        for (
$c=0;$c<=15;$c++) {

           
mkdir(dechex($a).'/'.dechex($b).'/'.dechex($c),0755);

        }

    }

}

?>
hinom - iMasters
19.09.2008 7:56
mkdir simple test with "exception handler"

<?php

function handleError() {
   
trigger_error('MY ERROR');

   
/** usage sample
        @handleError();
        echo $php_errormsg;
    */
}

// detect slash/backslash nomenclature dirname
$path = dirname( __FILE__ );
$slash = '/'; strpos( $path, $slash ) ? '' : $slash = '\\';
define( 'BASE_DIR', $path . $slash );

$folder  = time();               // folder name
$dirPath = BASE_DIR . $folder;   // folder path

// print results
echo $slash;
echo
'<hr>';

$rs = @mkdir( $dirPath, '0777' );
@
handleError();
if(
$rs )
{

   
// print success information
   
echo 'was done!';
    echo
'<br>folder: <a href="' . $folder . '">' . $folder . '</a>';
    echo
'<br>dirPath: ' . $dirPath;

}else{
   
   
// print error information
   
echo 'an error was occurred. Attempting create folder';
    echo
'<br>dirPath: ' . $dirPath;
    echo
'<br>php_errormsg: ' . $php_errormsg;

}

?>
php at mike2k dot com
15.07.2008 10:32
It should be noted that all of the recursive mkdir functions coded below are no longer required - as of 5.0.0 it says the "recursive" flag is available. I just tested it, it properly works (and I would assume it works for streams and Windows as well, if not, then it would be a bug)
GelaMu at GMail dot com
18.05.2008 2:19
<?php

/**
 * Makes directory and returns BOOL(TRUE) if exists OR made.
 *
 * @param  $path Path name
 * @return bool
 */
function rmkdir($path, $mode = 0755) {
   
$path = rtrim(preg_replace(array("/\\\\/", "/\/{2,}/"), "/", $path), "/");
   
$e = explode("/", ltrim($path, "/"));
    if(
substr($path, 0, 1) == "/") {
       
$e[0] = "/".$e[0];
    }
   
$c = count($e);
   
$cp = $e[0];
    for(
$i = 1; $i < $c; $i++) {
        if(!
is_dir($cp) && !@mkdir($cp, $mode)) {
            return
false;
        }
       
$cp .= "/".$e[$i];
    }
    return @
mkdir($path, $mode);
}

?>
php at msn dot net
8.03.2008 19:05
<?php

/**
 * Makes directory, returns TRUE if exists or made
 *
 * @param string $pathname The directory path.
 * @return boolean returns TRUE if exists or made or FALSE on failure.
 */

function mkdir_recursive($pathname, $mode)
{
   
is_dir(dirname($pathname)) || mkdir_recursive(dirname($pathname), $mode);
    return
is_dir($pathname) || @mkdir($pathname, $mode);
}

?>
code at ashleyhunt dot co dot uk
14.02.2008 20:15
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
david dot NOSPAM at ajnewmedia dot NOSPAM dot co dot uk
22.01.2008 6:04
p-garcia : since PHP 5, setting the recursive flag (which currently has no notes in the manual entry) will allow you to create nested directories in the same way as Windows / Linux mkdir -p, so long as the webserver has permissions to write in the root directory of the path specified
eg:

<?php
  mkdir
("./newdir1/newdir2/newdir3/", 0755, true);

 
// Returns TRUE if you have permission to write to the current directory
  //   and creates nested directories with permissionsrwxr-xr-x
?>
p-garcia at uniandes dot edu dot co
22.01.2008 2:45
After a long time trying to catch the cause of the warning: "mkdir() [function.mkdir]: No such file or directory", I finally realized that this function is not recursive; I mean, that if you want to create the folder -for example- c:\temp\t1\t2, you must do:
mkdir("c:\\temp\\t1") ;
mkdir("c:\\temp\\t1\\t2") ;

because mkdir is not like the windows mkdir where you can acomplish this in one single step.
Michal Nazarewicz, mina86 at mina86 dot com
27.08.2007 16:34
On the other hand, splitting path on something else then a DIRECTORY_SEPARATOR may give unexpected results when someone accualy wants a file name with backslash in it! Moreover, neither Alan's nor pluto's code check for errors or return any value. Also, I don't like the isset($folder[$i]) technique -- there is a count() function you know.

<?php
function recursive_mkdir($path, $mode = 0777) {
   
$dirs = explode(DIRECTORY_SEPARATOR , $path);
   
$count = count($dirs);
   
$path = '.';
    for (
$i = 0; $i < $count; ++$i) {
       
$path .= DIRECTORY_SEPARATOR . $dirs[$i];
        if (!
is_dir($path) && !mkdir($path, $mode)) {
            return
false;
        }
    }
    return
true;
}
?>

It will only fail if someone specifies a mode which does not allow owner to create new entries in directory.
kendsnyder at gmail dot com
4.05.2007 17:17
When creating directories in Windows, trailing periods (".") are ignored.  for example:

<?php

mkdir
('c:/Buck Jr.',0755);    // on Windows creates "c:/Buck Jr"
mkdir('c:/Elipses...',0755);  // on Windows creates "c:/Elipses"
mkdir('c:/php.com',0755);     // on Windows creates "c:/php.com"

?>

This is a Window's quirk, not a php shortcoming--meaning that you get the same results from a Window's command prompt.
glenn at bengeweb dot co dot nz
13.03.2007 6:00
I've discovered that since my (shared) hosting provider upgraded to PHP 5.1.6 , a script containing this mkdir doesn't work:

<?php
mkdir
('/home/benge/photos/gallery1/extra_large/', 0777);
?>

but this does work:
<?php
mkdir
('/home/benge/photos/gallery1/extra_large', 0777);
?>

the difference being, the trailing slash "/" after "extra_large.

There were three ways to fix the problem:
1. remove the trailing slash from the script code
2. downgrade to < PHP 5.1.6
3. turn safe mode off

I went with option 1.
sean at pedlr dot com
9.03.2007 5:58
It should be noted that although the documentation says that  the default permissions for mkdir are 0777, this is not always the case.

I'm running LAMP and without explicitly setting the permissions, the directories created had permissions of 0755.
Ari Schulman (ario [] mail utexas edu)
9.01.2007 0:02
Re: john 4t idserver d0t org, and djneoform at gmail dot com's posts from 27 Oct 2006:

On Windows systems, several keywords are reserved and cannot be used as filenames, in addition to just CON and PRN.  Attempting to create a folder with one of these names using mkdir will throw the unhelpful error "Invalid argument".  According to http://msdn.microsoft.com/library/default.asp ?url=/library/en-us/fileio/fs/naming_a_file.asp :

"Do not use the following reserved device names for the name of a file: CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Also avoid these names followed by an extension, for example, NUL.tx7.

    Windows NT:  CLOCK$ is also a reserved device name."

These keywords are also case-insensitive.  I don't know what problems are posed by using these keywords with extensions, but I successfully created a folder named "con_f".
fantasysportswire at yahoo dot com
21.12.2006 3:07
One small correction on a note from Frank in June 2006 on recursive directories under Windows.

First - this should be in the documentation as its the only function that I know of that php does not fix the slashes automatically.

Franks note stated:

<?php
   $mypath
="testdir\subdir\test";
  
mkdir($mypath,0777,TRUE);
?>

This doesn't work in windows:

<?php
   $mypath
="testdir/subdir/test";
  
mkdir($mypath,0777,TRUE);
?>

----

This will work a bit better :)

<?php
   $mypath
="testdir\\subdir\\test";
  
mkdir($mypath,0777,TRUE);
?>
PHGN
13.08.2006 20:13
I've been wrestling with mkdir on a server with safe mode turned on (I think, I kept getting barmy permissions on the new dirs).

In the end the solution was to use:
exec (mkdir ...
exec (chmod ...

For this to work I had to use the setuid bit on the script itself. I tried this with the mkdir() function, but to no avail. (To do the setuid bit I ran chmod 4775 on the script file from the command line.)
kungla at gmail dot com
18.07.2006 14:41
Somehow the recursive version of mkdir didn't work for me on Mac and the workaraounds listed below alsow didn't work for me, so heres my solution:

<?php
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);
    }
}
?>

Tested and works ;)
jamespilcher1hotmail
8.04.2006 14:53
one small gotcha:

mkdir(""), mkdir(false), and mkdir(null) give a "file exists" error. this is also true of a directory name consisting of any string that only contains space characters.

(this was on php 5.1.2 on Windows 2000)
bat at flurf dot net
22.03.2006 6:23
A little understanding of LISPlike programming makes this sort of task (recursive mkdir()ing in PHP4) much simpler.  This version works nicely:

<?php
function MakeDirectory($dir, $mode = 0755)
{
  if (
is_dir($dir) || @mkdir($dir,$mode)) return TRUE;
  if (!
MakeDirectory(dirname($dir),$mode)) return FALSE;
  return @
mkdir($dir,$mode);
}
?>

How it works: line one attempts to make the directory, and returns TRUE if it works or if it already exists.  That's the easy case if the parent directories all exist.

Line two trims off the last directory name using dirname(), and calls MakeDirectory recursively on that shorter directory.  If that fails, it returns FALSE, but otherwise we come out of it knowing that the parent directory definitely exists.

Finally, presuming the recursive call worked, once we get to line three we can create the requested directory.

Note the use of @ to suppress warning messages from mkdir.

The beauty of this is that if, say, the great-grandparent directory exists but the grandparent and parent directories don't, the function will simply call itself recursively until it gets high enough up the tree to do some work, then carry on unwinding back until all the new directories have been created.

This is pretty bog-standard recursive programming.  Anyone who can't wrap their head around it after a few minutes of concentration should probably try a career in sales.
Ali Baba
10.03.2006 22:26
Greg, your code does not work for me; maybe it has a bug or we have configuration changes. Anyway, this one works to create recursively the directory DIRECTORY.

<?
define
("DIRECTORY", "/tmp/mydir/mysubdir");

do {
   
$dir = DIRECTORY;
    while (!
is_dir($dir)) {
       
$basedir = dirname($dir);
        if (
$basedir == '/' || is_dir($basedir))
           
mkdir($dir,0777);
        else
           
$dir=$basedir;
   }
} while (
$dir != DIRECTORY);

?>

18.01.2006 18:48
function mkdirs($dir, $mode = 0777, $recursive = true) {
  if( is_null($dir) || $dir === "" ){
    return FALSE;
  }
  if( is_dir($dir) || $dir === "/" ){
    return TRUE;
  }
  if( mkdirs(dirname($dir), $mode, $recursive) ){
    return mkdir($dir, $mode);
  }
  return FALSE;
}
Sean at seanj dot jcink dot com
24.12.2005 3:10
Mkdir will work on parent directories as long as file permissions are right and the openbase restriction is not on.

~Sean
Kevin Cook
2.11.2005 18:14
I could not get the sticky bit set properly using the octal mode: 2775 (rwxrwsr-x)

$foo='my_directory';

$old_umask = umask(0);
mkdir($foo,2775);
umask($old_umask);

using the above lines renders a directory with permissions:

d-wx-wSrwt  2 www www 4096 Nov  2 11:43 my_directory

Not exactly what I was looking for.

This gets closer to the mark:

$foo='my_directory';

$old_umask = umask(0);
mkdir($foo,0777); // the default chmod
umask($old_umask);

drwxrwsrwx  2 www www 4096 Nov  2 11:46 my_directory
ephraim at coder-board dot info
11.10.2005 8:38
When safe_mode is enabled, and you create a directory via mkdir, you can't create a second inside the first because the first folder's user is that one of the webserver and not that one of the script. This is dumb and very annoying :(
funke
16.09.2005 21:51
Ive onlybeen coding in PHP for a couple of months so i Don't have all the syntax tricks down yet.

I wrote this function to create all the dirs in a path if they don't exist. its not actually recursive but i was to lazy to change the name  :)
theoretically i want it to work for both win and nix. As soon my project manager gets me a win box i'm gonna test it out.  anyrevisions to the function below would be appreciated.

<?php
// \

function recur_mkdirs($path, $mode = 0777) //creates directory tree recursively
{
   
//$GLOBALS["dirseparator"]
   
$dirs = explode($GLOBALS["dirseparator"],$path);
   
$pos = strrpos($path, ".");
    if (
$pos === false) { // note: three equal signs
       // not found, means path ends in a dir not file
       
$subamount=0;
    }
    else {
       
$subamount=1;
    }
   
    for (
$c=0;$c < count($dirs) - $subamount; $c++) {
       
$thispath="";
        for (
$cc=0; $cc <= $c; $cc++) {
           
$thispath.=$dirs[$cc].$GLOBALS["dirseparator"];
        }
        if (!
file_exists($thispath)) {
           
//print "$thispath<br>";
           
mkdir($thispath,$mode);
        }
       
       
    }
   
}
?>
roth at egotec dot com
23.05.2005 8:43
The 'mkdir' function doesn't function correctly on Windows when the path
contains forward slashes. The part of the path with the forward slashes
doesn't get created.

mkdir('c:/a/b/c/d', 0775, true);

You get the error message:
Warning: mkdir() [function.mkdir]: No such file or directory

Please use backslashes under Windows or use the constant DIRECTORY_SEPARATOR.

mkdir('c:\a\b\c\d', 0775, true);
mkdir('c:'.DIRECTORY_SEPARATOR.'a'.
DIRECTORY_SEPARATOR.'b'.
DIRECTORY_SEPARATOR.'c'.
DIRECTORY_SEPARATOR.'d', 0775, true);
webmaster2007 at home dot nl
28.04.2005 17:27
Maybe you can use this:

<?php
   
function open_dir($dir, $newdir){    //The function that will copy the files
       
if(file_exists($dir) && file_exists($newdir)){
           
$open_dir=opendir($dir);
            while (
false !== ($file = readdir($open_dir))) {
                if(
$file != "." && $file != ".."){
                    if(
file_exists($newdir."/".$file) && filetype($newdir."/".$file."/") != "dir"){
                       
unlink($newdir."/".$file);
                    }
                    if(
filetype($dir."/".$file."/") == "dir"){
                        if(!
file_exists($newdir."/".$file."/")){
                           
mkdir($newdir."/".$file."/");
                           
open_dir($dir."/".$file."/", $newdir."/".$file."/");
                        }
                    }
                    else {
                       
copy($dir."/".$file."/", $newdir."/".$file);
                    }
                }
            }
        }
    }
   
   
   
open_dir("Your source map", "Your destination map"); //Here you can fill in your source en destination map
?>
Protik Mukherjee
3.03.2005 18:29
mkdir, file rw, permission related notes for Fedora 3////
If you are using Fedora 3 and are facing permission problems, better check if SElinux is enabled on ur system. It add an additional layer of security and as a result PHP cant write to the folder eventhough it has 777 permissions. It took me almost a week to deal with this!

If you are not sure google for SElinux or 'disabling SELinux' and it may be the cure! Best of luck!

28.06.2003 13:00
You might notice that when you create a new directory using this code:

mkdir($dir, 0777);

The created folder actually has permissions of 0755, instead of the specified
0777. Why is this you ask? Because of umask(): http://www.php.net/umask

The default value of umask, at least on my setup, is 18. Which is 22 octal, or
0022. This means that when you use mkdir() to CHMOD the created folder to 0777,
PHP takes 0777 and substracts the current value of umask, in our case 0022, so
the result is 0755 - which is not what you wanted, probably.

The "fix" for this is simple, include this line:

$old_umask = umask(0);

Right before creating a folder with mkdir() to have the actual value you put be
used as the CHMOD. If you would like to return umask to its original value when
you're done, use this:

umask($old_umask);
aulbach at unter dot franken dot de
22.07.1999 23:37
This is an annotation from Stig Bakken:

The mode on your directory is affected by your current umask.  It will end
up having (<mkdir-mode> and (not <umask>)).  If you want to create one
that is publicly readable, do something like this:

<?php
$oldumask
= umask(0);
mkdir('mydir', 0777); // or even 01777 so you get the sticky bit set
umask($oldumask);
?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)