This one time, at band camp, Henri Marc <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I would like to use a variable instead of an image
> file name in a html page with this instruction:
>
> <?php
> echo '<img src="$myimage">';
> ?>
hmm, something like this may help for random images
<?php
// just so we know it is broken
error_reporting(E_ALL);
// set the images directory
$imgDir = './photos';
// open the image dir
$dir = opendir("$imgDir");
// read the files in the image dir
while (false !== ($file = readdir($dir)))
{
// make sure only image files are selected
$t = @getimagesize($imgDir.'/'.$file);
// there are now 16 image types supported
if ($file != "." && $file != ".." && $t['2'] < 17 &&
!is_dir($imgDir.'/'.$file))
{
// put the file names in an array
$file_array[] = $file;
}
}
// close the dir
closedir($dir);
// make sure there are files in the array :/
if(!isset($file_array))
{
echo 'No image files found';
}
else
{
// shuffle the array
shuffle($file_array);
// pick one off the top
$randImg = $file_array['0'];
// get the file info
$size = getimagesize ($imgDir.'/'.$randImg);
// open the file for reading
[EMAIL PROTECTED]($imgDir.'/'.$randImg, "rb");
// if everything is cool...
if ($size && $fp)
{
// set the headers
header("Content-type: {$size['mime']}");
// show the image
fpassthru($fp);
// bail out
exit;
}
else
{
// show an error
echo 'Sorry, No images available in '. $imgDir;
}
}
?>
--
______
(_____ \
_____) ) ____ ____ ____ ____
| ____/ / _ ) / _ | / ___) / _ )
| | ( (/ / ( ( | |( (___ ( (/ /
|_| \____) \_||_| \____) \____)
Kevin Waterson
Port Macquarie, Australia
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php