Random Images on webpage using php
#1
Posted 03 January 2006 - 10:04 AM
www.retrodesigner.co.uk/index.html
and the tutorial is
http://mikemania.kaw...iewtut.php?id=7
i can post the code if that ouwld help anyone solve this problem, thanks
#2
Posted 03 January 2006 - 10:38 AM
#4
Posted 03 January 2006 - 10:48 AM
#5
Posted 04 January 2006 - 07:15 AM
</head> <body> <div id="container"> <div id="header"> </div> <div id="menucontainer"> <ul id="menu"> <li id="active"><a href="index.html" id="current">About RD</a></li> <li><a href="Gallery.html">Gallery</a></li> <li><a href="news.html">RD News</a></li> <li><a href="contact.html">Contact RD</a></li> <li><a href="Links.html">Links</a></li> </ul> </div> <div id="content"> <div id ="uppercontent">Retrodesigner are the latest team to bring you high quality handpainted art. We are looking for more fans of the pop art revolution, so here at retrodesigner.co.uk you can see what we have to offer, by viewing our ever-growing gallery of original pop art.</div> <div id ="middlecontent"> <img src="http://www.retrodesigner.co.uk/images/randomimages/random.php"> </div> <div id ="lowercontent">Enter the gallery to see <a href="Gallery.html">more »</a></div> </div> <div id="footer">All work sold remains the copyright of Retrodesigner © 2004 </div> </div> </body> >and the php file code is
<?php
//directory here (relative to script)
$path = 'images\randomimages';
$i = 0;
$imgDir = opendir ($path);
while ( $file = readdir( $imgDir ) )
{
//checks that file is an image
$file_type = strrchr( $file, "." );
$is_image = eregi( "jpg|gif",$file_type );
if ( $file != '.' && $file != '..' && $is_image )
{ $images[$i++] = $file; }
}
closedir ($imgDir);
srand( (double) microtime()*1000000 );
$image_name = $path . '/' . $images[rand( 0,sizeof( $images ) -1 )];
$imgSize = GetImageSize( $image_name );
//ends script if no images found
if ( $i == 0 )
die();
//Display the image
readfile("$image_name");
?>
</html>
#6
Posted 04 January 2006 - 10:07 AM
$path = '\';problem is the script is looking for images in 'images/randomimages' while the script is already in there. So now its looking for images in 'images/randomimages/images/randomimages'.
Correct me if im wrong
#7
Posted 04 January 2006 - 10:39 AM
Avalanche, on Jan 4 2006, 03:07 PM, said:
$path = '\';problem is the script is looking for images in 'images/randomimages' while the script is already in there. So now its looking for images in 'images/randomimages/images/randomimages'.
Correct me if im wrong
i am new to PHP and was just following a tutorial that said put a path there so i can try and change it see what happens, thanks
will post results
that doesnt seem to have worked
Edited by donkeymusic, 04 January 2006 - 10:47 AM.
#8
Posted 04 January 2006 - 12:33 PM
#11
#12
Posted 04 January 2006 - 01:35 PM
Quote
That's what it's not working
Edited by Jaymz, 04 January 2006 - 01:45 PM.
#13
Posted 04 January 2006 - 01:46 PM
Jaymz, on Jan 4 2006, 06:35 PM, said:
Quote
That's what it's not working
totally lost now aint got a clue what that means
#14
Posted 04 January 2006 - 02:02 PM
Forgot to close your variables or w/e. Could be anything
#15
Posted 04 January 2006 - 02:43 PM
#16
Posted 07 January 2006 - 08:24 PM
<?php
//directory here (relative to script)
$path = './images\randomimages';
$i = 0;
$imgDir = opendir ($path);
$images = array();
while ( $file = readdir( $imgDir ) )
{
//checks that file is an image
$file_type = strrchr( $file, "." );
$is_image = eregi( "jpg|gif",$file_type );
if ( $file != '.' && $file != '..' && $is_image )
{
$images[$i++] = $file; }
}
closedir ($imgDir);
srand( (double) microtime()*1000000 );
$image_name = $path . '/' . $images[rand( 0,sizeof( $images ) -1 )];
$imgSize = GetImageSize( $image_name );
}
//ends script if no images found
if ( $i == 0 )
{
die();
}
else
{
//Display the image
readfile($image_name);
}
?>
Post if it doesn't work, I have not tested it.
#17
Posted 08 January 2006 - 08:49 AM
Chaos King, on Jan 8 2006, 01:24 AM, said:
<?php
//directory here (relative to script)
$path = './images\randomimages';
$i = 0;
$imgDir = opendir ($path);
$images = array();
while ( $file = readdir( $imgDir ) )
{
//checks that file is an image
$file_type = strrchr( $file, "." );
$is_image = eregi( "jpg|gif",$file_type );
if ( $file != '.' && $file != '..' && $is_image )
{
$images[$i++] = $file; }
}
closedir ($imgDir);
srand( (double) microtime()*1000000 );
$image_name = $path . '/' . $images[rand( 0,sizeof( $images ) -1 )];
$imgSize = GetImageSize( $image_name );
}
//ends script if no images found
if ( $i == 0 )
{
die();
}
else
{
//Display the image
readfile($image_name);
}
?>
Post if it doesn't work, I have not tested it.
That didnt seem to work, what should the images be labelled as
Edited by donkeymusic, 08 January 2006 - 08:50 AM.
#18 _*Raremandan_*
Posted 08 January 2006 - 10:16 AM
<?php
//directory here (relative to script)
$path = './images/randomimages';
$i = 0;
$imgDir = opendir ($path);
$images = array();
while ( $file = readdir( $imgDir ) )
{
//checks that file is an image
$file_type = strrchr( $file, "." );
$is_image = eregi( "jpg|gif",$file_type );
if ( $file != '.' && $file != '..' && $is_image )
{
$images[$i++] = $file; }
}
closedir ($imgDir);
srand( (double) microtime()*1000000 );
$image_name = $path . '/' . $images[rand( 0,sizeof( $images ) -1 )];
$imgSize = GetImageSize( $image_name );
}
//ends script if no images found
if ( $i == 0 )
{
die();
}
else
{
//Display the image
readfile($image_name);
}
?>
I'm not sure but I think there was a directory error. Try that although i've not tested it!
- Dan
#19
Posted 08 January 2006 - 10:45 AM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
