Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Please help me alter this PHP code


JamesS

Recommended Posts

Does anyone know how I could alter the code below to pull a *.txt, *.htm, *.html file rather than images? My PHP skills are not the greatest and I have been trying to manipulate this code for some time now by myself. Currently I am using this code to pull random images, but I thought it would be better utilized if I pulled a *.txt file with the image and text coded within it.

 

I also would need to know what code to enter in order to ('require/include/call') this new code since I will not be using this call anymore:

<img src="images/random/rid.php?pic=random1">

 

Thanks in advance for any support you can offer. The code I am currently using is listed here.

Here is a php script (I use) that will show random images

(could be altered to call text files and output to the screen)

 

<?php 

/*
A php script that will pick and show a number of random images

Create a folder called random

Put in any number of images you want - the script will find them

Copy, name script "rid.php" and install into the same folder as the images

use the following to  call the code into your desired page (edit style tags as needed, set to wrap text around it):

<img src="images/random/rid.php?pic=random1" border=0 alt=""style="float:right;padding-left:5px;padding-right:5px;padding-bottom:5px;padding-top:5px;background:white;border:1px solid white;">

to add more than one image just call it as pic=random2, pic=random3, pic=random4, etc....

*/
//read folder
$folder=opendir("."); 
while ($file = readdir($folder)) 
$names[count($names)] = $file; 
closedir($folder);
//sort file names in array
sort($names);
//remove any non-images from array
$tempvar=0;
for ($i=0;$names[$i];$i++){
$ext=strtolower(substr($names[$i],-4));
if ($ext==".jpg"||$ext==".gif"||$ext=="jpeg"||$ext==".png"){$names1[$tempvar]=$names[$i];$tempvar++;}
}
//random
srand ((double) microtime() * 10000000);
$rand_keys = array_rand ($names1, 2);
//random image from array
$slika=$names1[$rand_keys[0]]; 
//image dimensions
$dimensions = GetImageSize($slika); 
if (isset($HTTP_GET_VARS["pic"])){header ("Location: $slika");}
else {echo "<img src=\"$slika\" $dimensions[3]>";}
?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...