TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

April 16, 2024, 07:40:30 PM

Login with username, password and session length
Members
  • Total Members: 3,885
  • Latest: Growner
Stats
  • Total Posts: 195,161
  • Total Topics: 21,219
  • Online today: 106
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 65
  • Total: 65

Random images PHP block

Started by elpvn, April 28, 2006, 08:52:31 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

elpvn

Using this code (or download at the attachment file) to creat a image.php on your images_forlder and upload your images to there:

<?php
/*
*/
$dir=opendir("/home/yourname/public_html/images_forlder");
//This is the directory route to the folder
$directory="";
//This is a relative link to the directory if it is not in the same directory as the file you are displaying the images on


$pattern="\.(gif|jpg|jpeg|png|bmp|swf)%body%quot;;
if(!
$dir)
{
die("
Failed to read directory");
}
$s=readdir($dir);
$count="0";
$image;
while(
$s)
{
if(ereg(
$pattern$s))
{
$image[$count]=$s;
$count++;
}
$s=readdir($dir);
}
closedir(
$dir);

//Spit it out
$limit=count($image);
$limit--;
$randNum=rand(0,$limit);
$size=getimagesize("$directory$image[$randNum]");
echo "
<br><img src=\"$directory$image[$randNum]\" $size[3]>";
?>


After that, you can put this code to a PHP bloc


require("images_folder/image.php");


Have fun

P/s:
If need send messenge to SMS then try this one:
http://www.keyvan.net/code/sms-web-sender/ ;)

elpvn

Have an another way to creat a random images PHP block

Download this attachment file and change image URLs in list_img.txt and go on ... he heÃ,  :2funny:


G6Cad

Thank you for charing this Elvpn

elpvn

#3
Same that ones, to add a random banner (for advertise  >:D) or random links to your site (in a PHP block or an article) you can using attachments files below

;D <-- Now time for Z z z z ....

Crip

I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes



elpvn

one of them: http://www.master3d.net/arts/Compettions/image.php

Sorry but I don't want to creat more the demos for saving the BWÃ,  ;D

pheasant_plucker

I tried the first one, changing the directory route to my folder but it will not display an image. It reads the folder ok and chmod is 777 but I just get the red cross instead of an image. I have tried several images in different formats too in case it was them but it still will not work. All I have changed is the directory route to /home/rcmfco/public_html/cf4um/attachments image.php is in the attachments folder and put require("images_folder/image.php");Ã,  Ã,  Ã,  in a php block!

Any ideas???


Gerry

elpvn

Quote from: pheasant_plucker on April 28, 2006, 05:49:45 PM
I tried the first one, changing the directory route to my folder but it will not display an image. It reads the folder ok and chmod is 777 but I just get the red cross instead of an image. I have tried several images in different formats too in case it was them but it still will not work. All I have changed is the directory route to /home/rcmfco/public_html/cf4um/attachments image.php is in the attachments folder and put require("images_folder/image.php");Ã,  Ã,  Ã,  in a php block!

Any ideas???


Gerry

Try with


("/home/rcmfco/public_html/cf4um/attachments/");

and

include "randomimage.php";


Then how can I resize the images in PHP syntax ???

Rabain

Hi,

I'm looking for something like this except want I want to do is have a folder of images (all are very small animated gifs) that is called randomly into a block on the frontpage and each image is a link to the site the image belongs to.

Its basically like an advertisement and is for a game mod created by a specific mod site which I want visitors to my site to be able to visit by clicking the image of the mod advert.

Does something like this exist?  My search so far has only produced results that link directly to a larger version of the image in a folder/gallery.

jacortina

Becuase you need to link to a site, you can't simply pull file names out of a directory. You need to set up the relationship between image and the site it points to. But it really shouldn't be too hard.

All it should take is something like this:
global $boardurl;

$ad_gif_dir = $boardurl . '/ad_gifs'; <==== Specifies Sub-Dir off forum's home directory

$image_links[] = array('ad_gif' => 'name_of_file_A.gif',   'page_url' => 'http://site-linked-from-A.com');
$image_links[] = array('ad_gif' => 'name_of_file_B.gif',   'page_url' => 'http://site-linked-from-B.com/welcome.htm');
$image_links[] = array('ad_gif' => 'name_of_file_C.gif',   'page_url' => 'http://site-linked-from-C.com/home.php');
$image_links[] = array('ad_gif' => 'name_of_file_D.gif',   'page_url' => 'http://site-linked-from-D.com');
$image_links[] = array('ad_gif' => 'name_of_file_E.gif',   'page_url' => 'http://site-linked-from-E.com');
$image_links[] = array('ad_gif' => 'name_of_file_F.gif',   'page_url' => 'http://site-linked-from-F.com');
$image_links[] = array('ad_gif' => 'name_of_file_G.gif',   'page_url' => 'http://site-linked-from-G.com');
$image_links[] = array('ad_gif' => 'name_of_file_H.gif',   'page_url' => 'http://site-linked-from-H.com');
$image_links[] = array('ad_gif' => 'name_of_file_I.gif',   'page_url' => 'http://site-linked-from-I.com');
$image_links[] = array('ad_gif' => 'name_of_file_J.gif',   'page_url' => 'http://site-linked-from-J.com');
$image_links[] = array('ad_gif' => 'name_of_file_K.gif',   'page_url' => 'http://site-linked-from-K.com');

///////////////////////////////////////////////////////////////


$image_num = rand(0, (count($image_links)-1));

echo '<div align="center" valign="middle" width="100%">
          <a href="' , $image_links[$image_num]['page_url'] , '">
              <img border="0" src="', $ad_gif_dir, '/', $image_links[$image_num]['ad_gif'], '" />
          </a>
      </div>';


Specify the directory (code assumes that it's a subdir of the forum's directory) without a trailing slash.

Then enter the file / site pairs in the statements that follow.