: Prevent file table from showing navigation links I am trying to display the files in my folder, "Amir", but my table keeps displaying all of the files, "." and "..". How can I prevent my
I am trying to display the files in my folder, "Amir", but my table keeps displaying all of the files, "." and "..". How can I prevent my table from displaying ".." or "."? I have placed the code and a picture below.
<?php
echo '<table border="1">
<tr>
<th>Name</th>
</tr>';
if ($handle = opendir("amir")) {
//echo "Directory handle: $handlen";
//echo "Entries:n";
/* This is the correct way to loop over the directory. */
while (false !== ($entry = readdir($handle))) {
// echo "$entryn";
echo'
<tr>
<td><a href="'. $entry . '">'. $entry. '</a></td>
</tr>
';
}
/* This is the WRONG way to loop over the directory. */
while ($entry = readdir($handle)) {
//echo "$entryn";
}
closedir($handle);
}
echo'</table>
';
?>
More posts by @Phylliss660
1 Comments
Sorted by latest first Latest Oldest Best
Edit: Try this. (slightly simplified from [here])
<?php
// open this directory
$myDirectory = opendir("./");
// get each entry
while($entryName = readdir($myDirectory)) {
$dirArray[] = $entryName;
}
// close directory
closedir($myDirectory);
//count num files
$indexCount = count($dirArray);
Print ("$indexCount files<br>n");
//sort by name
sort($dirArray);
//print files
print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>n");
print("<TR><th>Filename</th><th>Filesize</th></TR>n");
// loop through the array of files and print them all
for($index=0; $index < $indexCount; $index++) {
if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files
print("<TR><TD><a href="$dirArray[$index]">$dirArray[$index]</a></td>");
print("<td>");
print(filesize($dirArray[$index]));
print("</td>");
print("</TR>n");
}
}
print("</TABLE>n");
?>
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.