note 94903 deleted from function.ftp-chmod by thiago
| From: | thiago@php.net | Date: | Wed, 02 Dec 2009 14:32:15 +0000 |
| Subject: | note 94903 deleted from function.ftp-chmod by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-163491@lists.php.net to get a copy of this message | ||
Note Submitter: miguel cudaihl
----
Here's the code that will create directories recursively.
# Recursively create directory via ftp
function CreateDirFtp($ftpConn, $path, $mode)
{
$mode = octdec( str_pad($mode,4,'0',STR_PAD_LEFT) );
# Get current dir
$currentDir = ftp_pwd($ftpConn);
# Change dir to root if path is from root$
if($path[0] == '/')
ftp_chdir($ftpConn, '/');
# Split path
$dirArray = explode('/', $path);
# Begin creating directories recursively
foreach($dirArray as $dir)
{
if(strlen($dir) > 0)
{
echo ftp_pwd($ftpConn) . '/' . $dir;
ftp_mkdir($ftpConn, str_replace(" ", "_", $dir));
ftp_chmod($ftpConn, $mode, $dir);
# Quit creation if chdir fails
if(ftp_chdir($ftpConn, str_replace(" ", "_", $dir)) == false)
break;
}
}
# chdir to originating dir
ftp_chdir($ftpConn, $currentDir);
}