从随机文件夹中选择随机图像

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 direct:

<?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()
    {
    $dir = showRandomDir();
    $list = scandir($dir);
    $fileRotateList = array();
    $img = '';
    foreach($list as $fileRotate)
        {
        if (is_file($dir . 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 = $dir . urlencode($fileRotateList[$imageNumber]);
        }

    return $img;
    }

When try to call the rotate2 function the output is only the random directory, without the image name:

Current output: /images/portfolio/randomDir

Should be: /images/portfolio/randomDir/randomImage.jpg