0

Hello All!
How can I automatically change permissions just for files in current directory and not for other directories. I suppose that 'chmod -R 664 .'
will change permission to all current directory content..

Edited by xolmc: n/a

2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by hashinclude
0

get the contents of the folder and use "is_dir()" in an "if" statement so that you would chmod files only
:)

0

get the contents of the folder and use "is_dir()" in an "if" statement so that you would chmod files only
:)

Have you some recursively snippet, please?

0

try something like this

$files =  scandir($dir_path);
foreach ($files as $file)
{
if(!is_dir($file))
{
chmod($file, 0664)
}
}
0

try something like this

$files =  scandir($dir_path);
foreach ($files as $file)
{
if(!is_dir($file))
{
chmod($file, 0664)
}
}

Thank you for answering.

Following recursive snippet works for me.

<?php

print_r(ReadFolderDirectory("/var/www" ));

function ReadFolderDirectory($dir = "" ) {

    $listDir = array();

    if($handler = opendir($dir)) {

        while (($sub = readdir($handler)) !== FALSE) {
            if ($sub != "." && $sub != ".." ) {

                if(is_file($dir."/".$sub)) {


                    chmod($dir."/".$sub, 0664);
                    
                    $listDir[] = $sub;

                }elseif(is_dir($dir."/".$sub)) {

                    $listDir[$sub] = ReadFolderDirectory($dir."/".$sub);

                }
            }

        }
        closedir($handler);
    }
    return $listDir;
}

?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.