You are here: Re: Include php and formatting of html code problems « All PHP « IT news, forums, messages
Re: Include php and formatting of html code problems

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">&nbsp;&nbsp; TEST
> TEST</font></b></td>
> </tr>
> <tr>
> <td width="100%" height="19">&nbsp;</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]


Удаленная работа для программистов  •  Как заработать на 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

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