Re: Problem with ocasional blank value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Jan 18, 2008 10:12 AM, Joey <Joey@xxxxxxxxx> wrote:
> Hi All,
>
>
>
> I have a problem that the below code which is supposed to display a random
> image and on occasion it shows NO image.
>
> I'm not sure what is happening.  This is running on linux just in case that
> makes any difference.
>
>
>
> <%
>
> $image_folder = "new_random/";
>
> $dir = $_SERVER['DOCUMENT_ROOT'] . "/" . $image_folder;
>
> $image_array = array();
>
>
>
> # The user doesn"t need to see any errors
>
> $dir_handle = @opendir($dir);
>
>
>
> while (false !== ($file = readdir($dir_handle)))
>
>   if (!is_dir($file))
>
>     $image_array[] = $file;
>
> #
>
> closedir ($dir_handle);
>
>
>
> #
>
> # The following appears to make things more random
>
> srand((double)microtime()*1000000);
>
> $r = rand(0,sizeof($image_array)-1);
>
>
>
> #
>
> echo "<img src=\"{$image_folder}{$image_array[$r]}\" width = \"561\" height
> = \"400\" >";
>
> %></td>
>
>
>
>
>
>
>
> Thanks!
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Why are you using ASP style tags?  PHP doesn't compile on it so what
other advantage does that give you other than not being compatible
with most installs?

Get rid of your error hiding.  Suppressing errors means you don't see
them either therefore cannot fix them.  The better solution is to turn
display_errors off and leave logging on.

My guess is that it is trying to link to a directory, a . hidden file,
or something else that shouldn't be there.  If it were my script I
would probably use a glob() type solution so that I can pick the ext's
I want.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux