Reading all the files from a particular directory and displays the files names/Links in a html list. (file ext: .pdf) I'm looking for output something like:
My code:
<ul>
<?php
$dir = '/my_directory_location';
$files = scandir($dir);
foreach ($files as $ind_file) {
?> <li> <a href="<?php echo $dir."/".$ind_file;?>"><?php echo $ind_file;?></li>
<?php } ?>
</ul>
Thanks in Advance
You probably need the glob()
in PHP
<?php
foreach (glob("*.pdf") as $filename) {
echo "$filename<br>";
}
OUTPUT :
resume1.pdf
resume4.pdf
resume5.pdf
try with this
$ARR_FILES = glob($PATH_TO_YOUR_DIRECTORY."/*.pdf");
foreach($ARR_FILES as $filename)
{
echo $filename."<br/>";
}