Jump to content

simple directory listing? supplied path not showing anything?


sayedsohail

Recommended Posts

Hi everyone,

 

function below just display files and folder but no the supplied path ie., http://localhost/xyz/ it just display files and folders where this script is saved not the supplied path.

 

Can someone please have a look at it.

 

Thanks,

<?php

function showContent($path){

   if ($handle = opendir($path))
   {
       $up = substr($path, 0, (strrpos(dirname($path."/."),"/")));
       echo "<tr><td colspan='3'>";
       echo "<a href='".$_SERVER['PHP_SELF']."?path=$up'>Up one level</a>";
       echo "</td></tr>";

       while (false !== ($file = readdir($handle)))
       {
           if ($file != "." && $file != "..")
           {
               $fName  = $file;
               $file   = $path.'/'.$file;
               
               if(is_file($file)) {
                   echo "<tr><td> -F- <a href='".$file."'>".$fName."</a></td>"
                            ."<td align='right'>".date ('d-m-Y H:i:s', filemtime($file))."</td>"
                            ."<td align='right'>".filesize($file)." bytes</td></tr>";
               } elseif (is_dir($file)) {
                   print "<tr><td colspan='3'> -D- <a href='".$_SERVER['PHP_SELF']."?path=$file'>$fName</a></td></tr>";
               }
           }
       }

       closedir($handle);
   }    

}

?>
        <table width="100%" border='1'>
<?php
$actpath ="http://localhost/";
            showContent("$actpath");        
?>
        </table>

i tried glob, but not sure how to make like proper listing in table with filename, filesize etc.  the code below just shows the results all in one row

 

<?php
$images = glob("../{*.jpg,*.gif,*.png,*.php}", GLOB_BRACE);


$dir = '../pdf/';

foreach(glob($dir.'*.*') as $file) {
    print $file . "\n";
}

foreach($images as $file2){
{
    print $file2 . "\n";
}


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.