A little changeable picture uses php guide

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
User avatar
Echo Dino
Registered User
Posts: 37
Joined: Fri Mar 22, 2019 11:09 am
Name: Saba
Contact:

A little changeable picture uses php guide

Post by Echo Dino »

probably you're using sig.grumpybumpers.com for having random images at every refresh. if you're hosting php supporter site you're able to do similar to this :D.


i'm using this three images(1,2,3): (probably gave you broken. visit the site to fix :) )

Image,Image
Image



and lets change them with every refresh! use that:

Code: Select all

<?php 

//variable

$id=mt_rand(0,2);
//Tell the browser that we are sending it a PNG image to display 
header("Content-Type: image/png"); 

//Echo with variables!
if ($id==0){
//Echo the contents of the image file called "dogbaby.png" to send it to the browser 
readfile("1.png"); 
}
elseif ($id==1){
//Echo the contents of the image file called "dogbaby.png" to send it to the browser 
readfile("2.png"); 
}
elseif ($id==2){
//Echo the contents of the image file called "dogbaby.png" to send it to the browser 
readfile("3.png"); 
}
?>
name that file to refreshimage.php
and our output is : (refresh to see another)
Image

Code: Select all

(make sure to put the link betwwen [img] and [/img]0



the "mt_rand(0,yournumber)" allows you to have random value between "0" and "yournumber" (if you choose 0 and 12 or anything. that will give one more (13)
Last edited by Echo Dino on Wed May 15, 2019 5:13 pm, edited 3 times in total.
User avatar
KevC
Support Team Member
Support Team Member
Posts: 72343
Joined: Fri Jun 04, 2004 10:44 am
Location: Oxford, UK
Contact:

Re: A little changeable picture uses php guide

Post by KevC »

Other than looking like an advert, what is this for?
-:|:- Support Request Template -:|:-
Image
"Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb"
User avatar
Echo Dino
Registered User
Posts: 37
Joined: Fri Mar 22, 2019 11:09 am
Name: Saba
Contact:

Re: A little changeable picture uses php guide

Post by Echo Dino »

KevC wrote: Wed May 15, 2019 12:01 pm Other than looking like an advert, what is this for?


it's a little thing for making pictures change with every refresh. i'm trying to make it with another pics without my hoster site :) .
User avatar
KevC
Support Team Member
Support Team Member
Posts: 72343
Joined: Fri Jun 04, 2004 10:44 am
Location: Oxford, UK
Contact:

Re: A little changeable picture uses php guide

Post by KevC »

What pictures where?
Your post makes no sense at all.
-:|:- Support Request Template -:|:-
Image
"Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb"
User avatar
Echo Dino
Registered User
Posts: 37
Joined: Fri Mar 22, 2019 11:09 am
Name: Saba
Contact:

Re: A little changeable picture uses php guide

Post by Echo Dino »

KevC wrote: Wed May 15, 2019 12:51 pm What pictures where?
Your post makes no sense at all.
that should be solved right now?
User avatar
Mannix_
Registered User
Posts: 1838
Joined: Sun Oct 25, 2015 2:56 pm
Name: Matt
Contact:

Re: A little changeable picture uses php guide

Post by Mannix_ »

KevC wrote: Wed May 15, 2019 12:51 pm What pictures where?
Your post makes no sense at all.
Every time your refresh this topic the image at the bottom of the first post changes
User avatar
AmigoJack
Registered User
Posts: 6108
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: A little changeable picture uses php guide

Post by AmigoJack »

Echo Dino wrote: Wed May 15, 2019 11:55 amuse that:
This tiny code alone oozes of redunancy. One principle when coding is DRY. One could easily make your code more efficient and flexible this way:

Code: Select all

<?php 

header( 'Content-Type: image/png' ); 

$id= mt_rand( 0, 2 );
readfile( $id. '.png' );
However, this whole topic is not phpBB related, it's only PHP related.
User avatar
Echo Dino
Registered User
Posts: 37
Joined: Fri Mar 22, 2019 11:09 am
Name: Saba
Contact:

Re: A little changeable picture uses php guide

Post by Echo Dino »

Code: Select all

<?php 

header( 'Content-Type: image/png' ); 

$id= mt_rand( 0, 2 );
readfile( $id. '.png' );


actually that doesn't work if file name not be number. but it's well code you've suggested :)
User avatar
Sniper_E
Registered User
Posts: 1134
Joined: Wed May 09, 2007 12:18 am
Location: Shreveport, Louisiana
Name: Ed Humphrey
Contact:

Re: A little changeable picture uses php guide

Post by Sniper_E »

There is a better random image script you could use. It handles all images.

viewtopic.php?p=15253906#p15253236
User avatar
AmigoJack
Registered User
Posts: 6108
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: A little changeable picture uses php guide

Post by AmigoJack »

Sniper_E wrote: Thu May 16, 2019 4:31 pmbetter
handles all images
No and no: it sends no MIME header, is very inefficient (loops of regexes, will also match directories with that extension). And you can't synonym "all" for just 3 types.
User avatar
Echo Dino
Registered User
Posts: 37
Joined: Fri Mar 22, 2019 11:09 am
Name: Saba
Contact:

Re: A little changeable picture uses php guide

Post by Echo Dino »

Sniper_E wrote: Thu May 16, 2019 4:31 pm There is a better random image script you could use. It handles all images.

viewtopic.php?p=15253906#p15253236


Isn't that very long? I got confused XD
Post Reply

Return to “phpBB Custom Coding”