Jump to content

simple directory listing? supplied path not showing anything?


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";
}


?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.