Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random Image Generator in PHP
Author Message
ZiNgA BuRgA
Smart Alternative

Posts: 17,022.2988
Threads: 1,174
Joined: 19th Jan 2007
Reputation: -1.71391
E-Pigs: 446.1274
Offline
Post: #1
Random Image Generator in PHP
Decided to put this up for anyone interested.

NOTE, requires:
  • A hosting service with PHP support
  • Images must be uploaded to the same folder as the PHP script

Copy and paste this to make a new .php file:

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php

// Force no caching
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Content-Type: image");








//****************** CHANGE THIS PART **************************
//Add lines to add images

$pic = array(
 "1.jpg",
 "2.jpg",
 "3.jpg"
);


//**************************************************************













$rpic = $pic[mt_rand(0, count($pic)-1)];

header("Content-Length: ".filesize($rpic));
header("Content-Type: image");

$fp = fopen($rpic, 'rb');
fpassthru($fp);
fclose($fp);

?>

Upload this file to your server, and direct people to use this .php file as the image.



I chose to use this method as it works better than a header redirect (which typically gets cached).  Also hides the actual files from the user :P

Further reference:
http://endlessparadigm.com/forum/showthread.php?tid=930

(This post was last modified: 01/04/2008 06:09 AM by ZiNgA BuRgA.)
26/03/2007 03:48 AM
Visit this user's website Find all posts by this user Quote this message in a reply
S7*
Sweet Dreams

Posts: 16,689.4373
Threads: 1,056
Joined: 3rd Apr 2007
Reputation: 14.29926
E-Pigs: 383.2309
Offline
Post: #2
RE: Random Image Generator in PHP
i CAN'T BELIEVE YOU!

I asked you loads, and you posted it here..

:(
:/
03/04/2007 04:52 AM
Find all posts by this user Quote this message in a reply
Ge64
Former Admin ;)

Posts: 3,163.4170
Threads: 295
Joined: 3rd Feb 2007
Reputation: 0.38918
E-Pigs: 108.4795
Offline
Post: #3
RE: Random Image Generator in PHP
lawl. yeah i did something with php and images some time ago, was a status image for a thread on a forum which showed the number of posts/pages in the thread and the last poster etc. turned out pretty cool
ty for sharing

also

http://crimsonomen.imeem.com/music/8-pwm..._has_aids/

[Image: ub1985584.jpg]
03/04/2007 06:16 AM
Find all posts by this user Quote this message in a reply
SXForce
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

Posts: 280.3000
Threads: 38
Joined: 20th Feb 2007
Reputation: 1.40616
E-Pigs: 5.6493
Offline
Post: #4
RE: Random Image Generator in PHP

03/04/2007 09:46 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Necro-Bot
Non-existent

 
Post: #5
Thread Revived!!!
[Image: screaming%20zombie.jpg]
11/04/2009 11:36 AM
Quote this message in a reply
Sparker
Super Lame Productions

Posts: 8,165.3369
Threads: 549
Joined: 19th Jan 2007
Reputation: 10.74638
E-Pigs: 187.9012
Offline
Post: #6
RE: Random Image Generator in PHP
I should use this sometime

11/04/2009 11:36 AM
Find all posts by this user Quote this message in a reply
RIKKU
Storm Trooper

Posts: 2,380.2478
Threads: 288
Joined: 12th Aug 2007
Reputation: -2.68834
E-Pigs: 69.6099
Offline
Post: #7
RE: Random Image Generator in PHP
2 yr old thread @_@
11/04/2009 09:27 PM
Find all posts by this user Quote this message in a reply
S7*
Sweet Dreams

Posts: 16,689.4373
Threads: 1,056
Joined: 3rd Apr 2007
Reputation: 14.29926
E-Pigs: 383.2309
Offline
Post: #8
RE: Random Image Generator in PHP
oh my god.

this was 2 YEARS AGO!?

Holy spoon.
12/04/2009 08:53 AM
Find all posts by this user Quote this message in a reply
feinicks
One day... we Fly...

Posts: 6,124.6050
Threads: 531
Joined: 27th Mar 2008
Reputation: 2.35695
E-Pigs: 210817.3958
Offline
Post: #9
RE: Random Image Generator in PHP
Yeah, its useful

◄◄••• 天使たちの夢か? •••►►

[Image: ewualizer.gif]
My works!
(This post was last modified: 12/04/2009 10:17 AM by S7*.)
12/04/2009 10:16 AM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 2 Guest(s)

 Quick Theme: