|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
why do i get this error?
Hi:
I was wondering if someone would be able to help me out? I have this script that calls random images form a given directory and I get this error when I run the script. Warning: mt_rand(): Invalid range: 0..0 Can someone please help me and tell me why I get this error and how I could fix it? Any help would be great! Code:
$imgpath = "path/to/image/dir";
$handle = opendir( "$imgpath" );
$imgArray = array();
while($file = readdir($handle))
{
if( $file != "." && $file != ".." )
{
array_push( $imgArray, $file );
}
}
closedir( $handle );
mt_srand( (double)microtime( ) * 1000000 );
$randval = mt_rand( 0, sizeof( $imgArray ) - 1 );
print"<IMG SRC="$imgpath/" . $imgArray[ $randval ] . "">";
|
|
#2
|
|||
|
|||
|
RE: why do i get this error?
Hmmm..that code works fine for me...are you sure that $imgpath is correct and that atleast 2 images are in that directory?
|
|
#3
|
|||
|
|||
|
RE: why do i get this error?
ok, it works if i have more then one image in that directory. but how would i make it so that if there is by chance only one image that i wouldnt get an error message?
-thanks matt! |
|
#4
|
|||
|
|||
|
RE: why do i get this error?
|
|
#5
|
|||
|
|||
|
RE: why do i get this error?
great thanks a million!
now i just have to figure out how to make it so it just looks for images ;-) |
|
#6
|
|||
|
|||
|
RE: why do i get this error?
|
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > why do i get this error? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|