Jump to content
  • Checkout
  • Login
  • Get in touch


The e-commerce.

Please help me alter this PHP code


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)



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
while ($file = readdir($folder)) 
$names[count($names)] = $file; 
//sort file names in array
//remove any non-images from array
for ($i=0;$names[$i];$i++){
if ($ext==".jpg"||$ext==".gif"||$ext=="jpeg"||$ext==".png"){$names1[$tempvar]=$names[$i];$tempvar++;}
srand ((double) microtime() * 10000000);
$rand_keys = array_rand ($names1, 2);
//random image from array
//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


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

  • Create New...