mardi 13 novembre 2018

How to display random image from random directory

Im trying to select random image from random directory. I make function to get random directory and another function to get random image from that directory. Okay, but its not working, its getting random directory and random image from another directory

PHP Beautifier Beautify and format your PHP code

Here is your PHP code :

Source

See as Text

<?php

function showRandomDir()
    {
    $files = glob('images/portfolio/*/', GLOB_ONLYDIR);
    shuffle($files);
    $files = array_slice($files, 0, 1);
    foreach($files as $file)
        {
        return $file;
        }
    }

function rotate2()
    {
    $list = scandir(showRandomDir());
    $fileRotateList = array();
    $img = '';
    foreach($list as $fileRotate)
        {
        if (is_file(showRandomDir() . htmlspecialchars($fileRotate)))
            {
            $ext = strtolower(pathinfo($fileRotate, PATHINFO_EXTENSION));
            if ($ext == 'gif' || $ext == 'jpeg' || $ext == 'jpg' || $ext == 'png')
                {
                $fileRotateList[] = $fileRotate;
                }
            }
        }

    if (count($fileRotateList) > 0)
        {
        $imageNumber = time() % count($fileRotateList);
        $img = showRandomDir() . urlencode($fileRotateList[$imageNumber]);
        }

    return $img;
    }




Aucun commentaire:

Enregistrer un commentaire