简体   繁体   中英

show files and directories in php

Hi I want to show to table my files and directories. And when it is files I want to show date of last update and size. Whats wrong with my code please?

<?
$whole_path = ("../directory/");

$dirFiles = array();
if ($handle = opendir($whole_path)) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." &&  $file != ".." && $file != "index.php" && $file != "Thumbnails") {
            $dirFiles[] = $file;
        }
    }
    closedir($handle);
}
sort($dirFiles);
foreach($dirFiles as $file => $value)
    {
    $name = basename($value);
    if(is_file($value))
          {
          $mod_date=date("d/m/Y H:i", filemtime($value));
          $size = filesize($value);
          }
?>

            <tr>
              <td><? echo $name; ?></td>
              <td><? echo $mod_date; ?></td>
              <td><? echo $size; ?></td>
            </tr>
<?}?>

You are not adding $whole_path to the filename, so is_file() is looking in the wrong place. $value = $whole_path . $value;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM