I want to create a PHP file that checks the current directory for any files ending in .jpg, and then I want to generate a page of links to all of those files.
<?php
$files = glob("./*.jpg");
if ($files) {
foreach ($files as $file) {
?>
<a href=<?php echo $file;?>"></a>
<?php }
?>
This is what I have, and it doesn’t do anything, and I’m not quite sure why. I’m quite new to learning php, so I’m not fantastic at it at this point.
Your anchor element needs to have some child element(s) inside of it, or else nothing will be displayed in your browser:
You also do need the
ifstatement, asglobsimply returns an empty array if no files are found, but you can add it back in if required.