|
Posted by Roger Bigras on 08/25/05 00:12
shorty wrote:
> All I am after is file:///C:/mypath/banner2.jpg in the following html
> code, to have an include statement added.
>
> I have tried everything I can think of.
>
> <body>
>
> <div align="center">
> <center>
> <table border="0" cellspacing="0" style="border-collapse: collapse"
> bordercolor="#111111" width="750" cellpadding="0" id="AutoNumber1"
> height="180">
> <tr>
> <td width="100%" background="file:///C:/mypath/banner2.jpg"
> height="161">
> <b><font size="6" color="#FF0000"> TEST
> TEST</font></b></td>
> </tr>
> <tr>
> <td width="100%" height="19"> </td>
> </tr>
> </table>
> </center>
> </div>
>
> </body>
>
>
> All this included php program does is randomly changes the background
> in a table cell, see below. The php code runs OK on its own.
>
> <?php
> /*
> * Name your images 1.jpg, 2.jpg etc.
> *
> * Add this line to your page where you want the images to
> * appear: <?php include "randomimage.php"; ?>
> */
>
> // Change this to the total number of images in the folder
> $total = "11";
>
> // Change to the type of files to use eg. .jpg or .gif
> $file_type = ".jpg";
>
> // Change to the location of the folder containing the images
> $image_folder = "images/random";
>
> // You do not need to edit below this line
>
> $start = "1";
>
> $random = mt_rand($start, $total);
>
> $image_name = $random . $file_type;
>
> echo "<img src=\"$image_folder/$image_name\" alt=\"$image_name\" />";
>
> ?>
>
> But i just cannot get the html formatting correct, Any ideas.
>
>
I've noticed that your using c:\ in your image path. this is not a good
idea, you should use your website's paths. Personally, I like to use
reletive paths such as ../ and ../../ etc...
Also, I've noticed that your using the image name as the alt tag.. this
will give you 1.jpg 2.jpg ... I'd probably leave the alt tag blank or
give it a text message.
finally, their is a method of changing the random images and keeping
your original image names and using the image name as a alt tag.
here is some code.
<?php
// Sample Code provided by Roger Bigras
$lnk = opendir("path2images"); //use a trailing slash /
$image_list = array();
while($file = readdir($lnk)){
if(is_file($path2images.$file)){
array_push($image_list,$path2images.file);
}
}
$random = mt_rand(0, ($image_list)-1);
$alt = basename($image_list[$random]);
$use = $image_list[$random];
echo "<img src='$use' alt='$alt'>";
?>
Navigation:
[Reply to this message]
|