Hi,
long time ago I posted a question about creating a CMS which would write standard .htm files to the server so negating the need for long ?url variables which Google doesn't like! Anyhoo, having created a system which does all of this, I was wondering is there a way to set file permissions on multiple files on the server. I know that I can use CHMOD with php, but the script examples on php.net just show setting an individual file. Is there a way of using wildcards e.g. *.htm etc?
cheers,
Mike
Setting file permissions with PHP
Moderator: General Moderators
this scans the directory of your choice, and matches all files that end in htm(this wont match html)
then it chmod's all the matches
if you need it to match more than 1 type of file ext let us know, its easy
then it chmod's all the matches
if you need it to match more than 1 type of file ext let us know, its easy
Code: Select all
<?php
$dir_name = 'cache';
$dir = dir($dir_name);
$documents = array();
while (false !== ($document = $dir->read())) {
if ('htm' === end(explode('.', $document))) {
$documents[] = $document;
}
}
$dir->close();
foreach ($documents as $doc) {
chmod("$dir_name/$doc", 0777);
}
?>Nice one, thanks for that
Is it possible to chmod a directory. I've used chmod in php in the form of
This works well and the mode of 'filename.php' is changed. But if I simply change my script to:
The permissions for the 'mydirectory' directory don't get changed. Is there a different syntax when working with directories as distinct from files? (incidently, I've tried it with and without the trailing slash)
cheers,
Mike
Is it possible to chmod a directory. I've used chmod in php in the form of
Code: Select all
chmod("$filepath/mydirectory/filename.php", 775);Code: Select all
chmod("$filepath/mydirectory/", 775);cheers,
Mike
What directory class are you using?rehfeld wrote:Code: Select all
<?php $dir->close(); ?>