note 40786 deleted from function.ftp-chmod by nlopess
| From: | nlopess@php.net | Date: | Mon, 15 Mar 2004 14:10:33 +0000 |
| Subject: | note 40786 deleted from function.ftp-chmod by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-66865@lists.php.net to get a copy of this message | ||
Note Submitter: tenphp@hallvord.com
----
I needed to do a recursive chmod on a set of folders, subfolders and files on a server where I have
a hosting account without any shell access. This function helps. Call it with the connection as the
first parameter and the folder to start from as the second. Not exactly fast (you probably want to
include a set_time_limit() to avoid a timeout.)
<?php
function recursive_chmod_with_ftp($connection, $basefolder){
$files = ftp_nlist($connection,$basefolder); //get files in directory
foreach ($files as $file) {
$isfile = ftp_size($connection, $file);
if($isfile == "-1") { //Is a file or a folder?
ftp_site ( $connection, 'CHMOD 777 '.$file);
recursive_chmod_with_ftp($connection, $file); // a folder! Keep going down!
}else {
ftp_site ( $connection, "CHMOD 777 '.$file);
echo "CHMODed $file";
}
}
}
?>