• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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