You are here: Re: PHP image rotator ... « All PHP « IT news, forums, messages
Re: PHP image rotator ...

Posted by dimo414 on 09/03/06 20:04

Rob wrote:
> Hi,
>
> I'm a webbie, but new to php.
>
> DL'd a script which is a random image rotator. (below).
> Inserted the path to my images folder, tried it on 2 servers but get error
> on both:
> "Warning: getimagesize: Unable to open 'image5.jpg' for reading..."
> "Warning: getimagesize(2.jpg) [function.getimagesize]: failed to open
> stream: No such file or directory ..." The image files were named in the
> error messages, so the srcript found them, but "getimagesize" seems to be an
> issue. Is this a CHMOD thing..... or...?
>
> Can anyone give me some help with this?
> My folder pathway (relative) is in the 1st "$folder..." line ..
>
> ==============BEGIN SCRIPT==================
> <?php
> //READ FOLDER
> $folder=opendir("images/art_shows");
> while ($file = readdir($folder))
> $image_names[count($image_names)] = $file;
> closedir($folder);
>
> //SORT FILE NAMES
> sort($image_names);
>
> //REMOVE ANYTHING IS NOT AN IMAGE FROM THE RANDOM LIST (EXTENTION GIF, JPG,
> JPEG AND PNG)
> $rem=0; //tempvar
> for ($i=0;$image_names[$i];$i++)
> {
> $extention=strtolower(substr($image_names[$i],-4));
> if
> ($extention==".gif"||$extention==".jpg"||$extention=="jpeg"||$extention==".png")
> {
> $image_names1[$rem]=$image_names[$i];$rem++;
> }
> }
>
> // RANDOM FUNCTION
> srand ((double) microtime() * 10000000);
> $jrand = array_rand ($image_names1, 2);
>
> //RANDOM IMAGE FROM THE LIST
> $jprandom=$image_names1[$jrand[0]];
>
> // IMAGE SIZE
> $image_size = getimagesize($jprandom);
> if (isset($HTTP_GET_VARS["image"])){header ("Location: $jprandom");}
> else {echo "<img src=\"$jprandom\" $image_size[3]>";}
> ?>
>
> ====================END OF SCRIPT============
>
> thanks!

//READ FOLDER
$folderRoot = 'images/art_shows';
$folder=opendir($folderRoot);
while ($file = readdir($folder))
$image_names[count($image_names)] = $folderRoot . $file;
closedir($folder);

I added a variable $folderRoot and prepended it to the value of file.
readdir() is a great function, but only returns the name of the file,
not it's location, so you need to prepend the location relative to the
current script in order for the files to be called anywhere else.

Hopefully that'll work.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация