Need help with small random image PHP script
Posted: Thu Aug 25, 2011 1:02 pm
Hello everyone, this is my first post so I'll try to be as classy as possible!
I'm learning PHP programming and would like some help completing this very small project.
What I have is an index.php which includes another php file that displays a random image from a specific folder. Here is the actual code.
barbie.php (main index.php file)
and here is the rotating script
rotate155.php
but I get this error
I've been researching how to use includes, requires php.ini, path_include I just can't find out how to make this work though, any help please?
Thank you very much for your time and effort!
I'm learning PHP programming and would like some help completing this very small project.
What I have is an index.php which includes another php file that displays a random image from a specific folder. Here is the actual code.
barbie.php (main index.php file)
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<Title>PHP Demo</Title>
</head>
<body>
<?php include($_SERVER['DOCUMENT_ROOT']."images/rotate155.php"); ?>
</body>
</html> rotate155.php
Code: Select all
<?
$imglist='';
//$img_folder is the variable that holds the path to the banner images. Mine is images/tutorials/
// see that you don't forget about the "/" at the end
$img_folder = "/155/";
mt_srand((double)microtime()*1000);
//use the directory class
$imgs = dir($img_folder);
//read all files from the directory, checks if are images and ads them to a list (see below how to display flash banners)
while ($file = $imgs->read()) {
if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
$imglist .= "$file ";
} closedir($imgs->handle);
//put all images into an array
$imglist = explode(" ", $imglist);
$no = sizeof($imglist)-2;
//generate a random number between 0 and the number of images
$random = mt_rand(0, $no);
$image = $imglist[$random];
//display image
echo '<img src="'.$img_folder.$image.'" border=0>';
?>but I get this error
Code: Select all
Warning: include(/home/evilpspc/public_html/barbie.theendstudios.comimages/rotate155.php) [function.include]: failed to open stream: No such file or directory in /home/evilpspc/public_html/barbie.theendstudios.com/barbie.php on line 10
Warning: include() [function.include]: Failed opening '/home/evilpspc/public_html/barbie.theendstudios.comimages/rotate155.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/evilpspc/public_html/barbie.theendstudios.com/barbie.php on line 10I've been researching how to use includes, requires php.ini, path_include I just can't find out how to make this work though, any help please?
Thank you very much for your time and effort!