This is somewhat similar to some index pages. When new file or folder is added to the directory, HTML page should display the newly created file/folder together with previous ones after it is being refreshed. (prefer in alphabatical order)
How to achieve this sort of functionality in PHP? Please provide sample coding as well. (and any references)
this is rather easy, here you go:
$files = scandir('./directory/to/list');
sort($files); // this does the sorting
foreach($files as $file){
echo'<a href="/directory/to/list/'.$file.'">'.$file.'</a>';
}
this should give you a basic idea what to do.
Pretty much a direct rip from the manual:
<?php
$d = dir(".");
echo "Path: " . $d->path . "\n";
echo "<ul>";
while (false !== ($entry = $d->read())) {
echo "<li><a href='{$entry}'>{$entry}</a></li>";
}
echo "</ul>";
$d->close();
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With