note 37296 modified in function.mkdir by aidan

From: Date: Sun, 03 Oct 2004 13:32:49 +0000
Subject: note 37296 modified in function.mkdir by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-77821@lists.php.net to get a copy of this message
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. --was-- 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: // create directory through FTP connection function FtpMkdir($path, $newDir) { $server='ftp.yourserver.com'; // ftp server $connection = ftp_connect($ftp_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. http://php.net/manual/en/function.mkdir.php

« previous php.notes (#77821) next »