Search code examples
php-5.3phpdesigner

is_writable($dir) not working


when I was working with thix thix ix all fine it ix showing all the subfolder and than subfolders of the subfolders

<?php

function listFolderFiles($dir){
    $Folders = scandir($dir);
    echo '<ol>';
    foreach($folders as $subFolders){
        if($subFolders != '.' && $subFolders != '..'){
             echo '<li>'.$subFolders;
             if(is_dir($dir.'/'.$subFolder)) listFolderFiles($dir.'/'.$subFolders);
             echo '</li>';
         }
    }

    echo '</ol>';
}

listFolderFiles('/home/');

?>

but when i changed the code a little bit to check whether any folder is writable than it gave me nothing neither an error nor shown the results.. at the line

if($subFolders != '.' && $subFolders != '..'){
                if(is_writable($subFolders)){
        echo '<li>'.$subFolders.' is witeable :) ';

Solution

  • You're close, but missing the full file name. Need the $dir.'/'. part (the parent path):

    if(is_writable($dir.'/'.$subFolders)){