Good afternoon, comrades.
It is necessary to display the contents of the folder using PHP, an example of an idea:
There is a path / img folder.
It is necessary that all files in the folder are displayed as follows:
<a href="/path/img/file1.jpg"><img src="/path/img/file1.jpg"/></a> <a href="/path/img/file2.jpg"><img src="/path/img/file2.jpg"/></a> I myself do this:
<? $current_dir = '/home/site/public_html/pages/gallery/img/'; $dir = opendir($current_dir); while ($file = readdir($dir)) { echo "<img src=\"/path/img/$file\" width=\"250px\"/>"; } closedir($dir); ?> The result of my code:
<img src="/path/img/." width="250px"> <img src="/path/img/IMG_6155.JPG" width="250px"> <img src="/path/img/.." width="250px"> My version with errors - from somewhere extra lines of code were added with a ".".
Please help with this task.
Thank you for attention!