Link to home
Create AccountLog in
Avatar of usmbay
usmbayFlag for United States of America

asked on

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;
}
ASKER CERTIFIED SOLUTION
Avatar of hernst42
hernst42
Flag of Germany image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of usmbay

ASKER

it display nothing
Avatar of usmbay

ASKER

ok it works
I change $path eith $path_to_images

Thanks
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