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

Posts: 12,608
Threads: 823
Joined: 19th Jan 2007
Reputation: 126
E-Pigs: 324.8437 EP
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
Senseito7
Bleeding in Secret
Team DreamArts

Posts: 14,045
Threads: 903
Joined: 3rd Apr 2007
Reputation: 74
E-Pigs: 218.2814 EP
Online
Post: #2
RE: Random Image Generator in PHP
i CAN'T BELIEVE YOU!

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

:(
:/

< What Anime am I talking about?
feeling..
..together
never..
forevermore
I can't see you anymore...
... where have you gone?... I need you...

Spoiler:
[Image: ayuayu.png][Image: thelonesakurasig.png]
03/04/2007 04:52 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Ge64
Fixes PSP, NDSL, iPod!

Posts: 3,352
Threads: 280
Joined: 3rd Feb 2007
Reputation: 49
E-Pigs: 58.2661 EP
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: 468x60_dday.png]

[Image: getextwv8.png][Image: bang-head-on-keyboard.gif]

Awesome! Thanks Diego!!

Code:
1
2
3
4
5
6
7
8
9
ACHTUNG! Alles touristen und non-technischen lookenpeepers!

  Das machine control is nicht fur gerfingerpoken und
  mittengrabben. Oderwise is easy schnappen der springenwerk,
  blowenfusen, und poppencorken mit spitzensparken.
  Der machine is diggen by experten only. Is nicht fur
  geverken by das dummkopfen. Das rubbernecken sichtseenen
  keepen das cottenpicken hans in die pockets,
  so relaxen und watchen das blinkenlights.

03/04/2007 06:16 AM
Visit this user's website Find all posts by this user Quote this message in a reply
SXForce
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

Posts: 288
Threads: 38
Joined: 20th Feb 2007
Reputation: 7
E-Pigs: 3.7760 EP
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

 
E-Pigs:
Post: #5
Thread Revived!!!
[Image: screaming%20zombie.jpg]
11/04/2009 11:36 AM
Quote this message in a reply
Sparker
Mahō Shōjo Lolita Sparkito

Posts: 8,726
Threads: 454
Joined: 19th Jan 2007
Reputation: 72
E-Pigs: 71.7762 EP
Offline
Post: #6
RE: Random Image Generator in PHP
I should use this sometime

I am a Magical Girl!
[Image: msls.png]
My magical laser attack!
[Image: 29fs19c.gif]
NO MOOR SRS BSNZ IN T3H VOID
[Image: 37568219.png]
11/04/2009 11:36 AM
Visit this user's website Find all posts by this user Quote this message in a reply
V-chan
Formerly Rukia

Posts: 2,120
Threads: 240
Joined: 12th Aug 2007
Reputation: 36
E-Pigs: 38.6215 EP
Offline
Post: #7
RE: Random Image Generator in PHP
2 yr old thread @_@

It's a ME a RUIKIA!
11/04/2009 09:27 PM
Find all posts by this user Quote this message in a reply
Senseito7
Bleeding in Secret
Team DreamArts

Posts: 14,045
Threads: 903
Joined: 3rd Apr 2007
Reputation: 74
E-Pigs: 218.2814 EP
Online
Post: #8
RE: Random Image Generator in PHP
oh my god.

this was 2 YEARS AGO!?

Holy chocolate.

< What Anime am I talking about?
feeling..
..together
never..
forevermore
I can't see you anymore...
... where have you gone?... I need you...

Spoiler:
[Image: ayuayu.png][Image: thelonesakurasig.png]
12/04/2009 08:53 AM
Visit this user's website Find all posts by this user Quote this message in a reply
MysterySword
Paradoxical Absurdity

Posts: 766
Threads: 24
Joined: 19th Oct 2008
Reputation: 8
E-Pigs: 31.7039 EP
Offline
Post: #9
RE: Random Image Generator in PHP
Still interesting PHP nonetheless :)

May come in handy

[Image: 934599566.png]

"Twilight. The story of a young woman's choice to practice either bestiality or necrophilia."
12/04/2009 09:36 AM
Find all posts by this user Quote this message in a reply
feinicks
One day... we Fly...

Posts: 6,601
Threads: 530
Joined: 27th Mar 2008
Reputation: 34
E-Pigs: 210,797.1760 EP
Offline
Post: #10
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 Senseito7.)
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: 1 Guest(s)

 Quick Theme: