• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

IMAGE FILE NAME

HOW I GET THE IMAGE FILE  NAME FROM THIS FUNCTION


function getRandomImage($path, $img) {
    if ( $list = getImagesList($path) ) {
        mt_srand( (double)microtime() * 1000000 );
        $num = array_rand($list);
        $img = $list[$num];
    }
    return $path . $img;
}

function getImagesList($path) {
    $ctr = 0;
    if ( $img_dir = @opendir($path) ) {
        while ( false !== ($img_file = readdir($img_dir)) ) {
            // can add checks for other image file types here
            if ( preg_match("/(\.gif|\.jpg)$/", $img_file) ) {
                $images[$ctr] = $img_file;
                $ctr++;
            }
        }
        closedir($img_dir);
        return $images;

    }
    return false;
}
0
usmbay
Asked:
usmbay
  • 2
  • 2
1 Solution
 
hernst42Commented:
See http://www.php.net/basename

echo basename(getRandomImage($path, $img));
0
 
usmbayAuthor Commented:
it display nothing
0
 
usmbayAuthor Commented:
ok it works
I change $path eith $path_to_images

Thanks
0
 
hernst42Commented:
objection, as the code you posted does not included how you use function I couldn't give you that adive. as you state in http:#20025105 it works with basename (and that was what you asked for) I think I deserve that points
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now