PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<lstatmove_uploaded_file>
view the version of this page
Last updated: Thu, 15 Jul 2004

mkdir

(PHP 3, PHP 4 , PHP 5)

mkdir -- Maakt een folder aan

Beschrijving

bool mkdir ( string pathname [, int mode])

Probeert de folder pathname aan te maken.

Waarschijnlijk wil je de mode als een octale waarde meegeven, wat betekent dat je er een begin 0 voor moet zetten. De mode wordt ook bewerkt door de huidige umask, die je kan veranderen met umask().

Opmerking: Mode wordt genegeerd onder Windows, en is optioneel geworden in PHP 4.2.0.

De modus is standaard 0777, wat de breedst mogelijke toegang betekent. Voor meer informatie over modus, lees de details op de chmod() pagina.

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

Geeft TRUE terug bij succes, FALSE indien er een fout is opgetreden.

Zie ook rmdir().



add a note add a note User Contributed Notes
mkdir
ramonklown at pop dot com dot br
16-Nov-2004 06:59
Right after you make a dir you should put chdir in order to be able to read that dir, otherwise you get an error message.

$dirupload = 'D:/server/images/';

mkdir ($dirupload, 0700);

chdir('./');

Hope it helps someone.

Peace,
Ramon
andrei at bizland dot ro
24-Oct-2004 06:33
Here is a better function to create multiple directories :

   function mkDirE($dir,$dirmode=700)
   {
       if (!empty($dir))
       {
           if (!file_exists($dir))
           {
               preg_match_all('/([^\/]*)\/?/i', $dir,$atmp);
               $base="";
               foreach ($atmp[0] as $key=>$val)
               {
                   $base=$base.$val;
                   if(!file_exists($base))
                       if (!mkdir($base,$dirmode))
                       {
                               echo "Error: Cannot create ".$base;
                           return -1;
                       }
               }
           }
           else
               if (!is_dir($dir))
               {
                       echo "Error: ".$dir." exists and is not a directory";
                   return -2;
               }
       }

       return 0;

   }
aidan at php dot net
03-Oct-2004 04:17
This function creates a directory structure recursively.

http://aidan.dotgeek.org/lib/?file=function.mkdirr.php
Han Van den Hoof
09-Nov-2003 07:28
If you're on a shared *nix server, a directory created through mkdir() will not be assigned to you, but to the user that your host's server or php process is running under, usually 'nobody', 'apache' or 'httpd'.

In practice, this means that you can create directories, even add files to them, but you can't delete the directory or its contents nor change permissions.

It is therefore advised to create directories through PHP's FTP API. Here's a function I wrote:

<?php
// create directory through FTP connection
function FtpMkdir($path, $newDir) {
  
      
$server='ftp.yourserver.com'; // ftp server
      
$connection = ftp_connect($server); // connection
  
 
       // login to ftp server
      
$user = "me";
      
$pass = "password";
      
$result = ftp_login($connection, $user, $pass);

  
// check if connection was made
    
if ((!$connection) || (!$result)) {
       return
false;
       exit();
       } else {
        
ftp_chdir($connection, $path); // go to destination dir
      
if(ftp_mkdir($connection,$newDir)) { // create directory
          
return $newDir;
       } else {
           return
false;       
       }
  
ftp_close($conn_id); // close connection
  
}

}
?>

Hope this comes in handy for someone.
timo dot hummel at 4fb dot de
06-Oct-2003 05:20
mkdir will create directories with undesired/unexpected owner/group settings in certain circumstandes when SAFE_MODE is on. See the bug report: http://bugs.php.net/bug.php?id=24604
28-Jun-2003 01: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-Jul-1999 11: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);
?>

<lstatmove_uploaded_file>
 Last updated: Thu, 15 Jul 2004
show source | credits | stats | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This mirror generously provided by: NedLinux
Last updated: Fri Feb 4 17:11:33 2005 CET