Reputation: 147
Simple question that I'm not sure how to ask google:
If I have a folder for each user on my website, and each folder has only 1 jpg picture in it ( along with other different, currently unimportant files ),
Is there an easy way to display that img without actually specifying the name of the jpg file? eg.
<img src="http://www.domain.com/users/315/*.jpg>
Or would I have to use php scandir on the directory each time to get the specific name?
Sorry if duplicate, I wasn't able to find an answer elsewhere and wasn't sure how to actually search this. Thanks.
Upvotes: 0
Views: 104
Reputation: 1358
I'd say use scandir (add the relative path to your directory is instead of "img"):
<?php
$dir = 'img';
$file = scandir($dir, 1);
?>
<img src="img/<?= $file[0]; ?>">
More on scandir here.
Upvotes: 1