简体   繁体   中英

Displaying an image from a href

<a href="image.jpg">image.jpg</a>

There is a load of lines like this with different pictures. What i need to do is to make a script of some sort that would allow displaying those images without the need to write anything new in the body (it has to find the files from href's and display them ... without causing any more work for a person who puts those pictures there) and without the need to reorganize files (those files are tied to many other things ... change in the directory = everything crashes) but i cant just find much ... most of the scripts i find requires me to place files in a specific folder or even worse ... to make img src tags for them

Can anyone point me towards some solution here ?

I'm not exactly clear on the question, but if I decipher it correctly a possible solution is to user scandir to read the contents of a directory. Likely will need to modify inside the foreach loop to fit your design (not sure if you have embedded script or not) but this will dynamically fetch and display images inside a directory.

if ($images = scandir('path_to_your_image_directory')) {
    foreach ($images as $image) {
        print '<a href="$image">$image.jpg</a>'; // Might need to preface the $image variable with path to your image directory
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM