<?php
error_reporting(0);

if (isset($_GET['file']) && isset($_POST['data'])){
    //need to get form data and write to the file
    $newdata = $_POST['data'];
    if ($newdata != ''){
    $fh = fopen($_GET['file'],'w');
    fwrite($fh,$newdata);
    fclose($fh);
    }
    
    
}
?>
<form action="<?php echo basename($_SERVER['PHP_SELF']).'?'.$_SERVER['QUERY_STRING'];?>" method="post">
<textarea name="data" cols="60" rows="10">
  <?php
  echo file_get_contents($_GET['file']);  
  ?>    
    
</textarea>     
<input type="submit" name="submit" value="update">    
</form>    
<?php
    // Open a known directory, and proceed to read its contents

function recurse($dir,$levels = 0){
   
    $marginleft = $levels * 20;
    echo 'levels are '.$levels.'<br>'; 
      if ($dh = opendir($dir)) {
         sort($dh);
            while (($file = readdir($dh)) !== false) {
                
                if ($file == '.' || $file== '..' || $file == '.DS_Store') continue;
                if (is_dir($dir.'/'.$file)){
                    $path = $dir.'/'.$file;
                    $slashes = count(explode('/',$path)) - 1;
                    echo 'Directory: '.$dir.'/'.$file.'<br>';
                    recurse($dir.'/'.$file,$slashes);
                }
                else {
               //test folder...if it is a directory call function and send new path
                //else
             echo   '<span style="margin-left: '.$marginleft.'px;"><a href="'.$dir.'/'.$file.'">Visit '.$file.'</a>'; 
             if (getimagesize($dir.'/'.$file)){
                echo '<img src ="'.$dir.'/'.$file.'" height="50">'; 
             }
                    
             if (strpos($file,'.php')){
             echo '<a href="cms.php?file='.$dir.'/'.$file.'"> Edit '.$file.'</a>';
             }
            echo  '</span><br>';        
                    
             
                }
             }
           
            closedir($dh);
        }
    }

recurse('.');
?>
   

  