Read images from a directory using PHP

后端 未结 6 534
广开言路
广开言路 2020-12-19 16:35

I am wanting to find out if the following is possible with PHP inside WordPress.

Basically if I have a directory in my site called \"promos\" that consists of 1 to

6条回答
  •  青春惊慌失措
    2020-12-19 17:05

    Assuming that all files in the promos directory are images:

    "; echo ""; echo "
    "; } closedir($handle); } ?>

    If, however, there are files in the directory that are not images, you would need to check that before showing it. The while loop would need to change to something like:

    while (false !== ($file = readdir($handle))) {
        if ((strpos($file, ".jpg")) || (strpos($file, ".gif"))) {
            echo "
    "; echo ""; echo "
    "; } }

提交回复
热议问题