Button to retrieve and display an image?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
boondox
Forum Newbie
Posts: 20
Joined: Wed Oct 08, 2008 4:58 am

Button to retrieve and display an image?

Post by boondox »

Ok what I want is a button that retrieves an image from my server and then displays it on one of my websites pages..


Basically what I want is a way to just push a button that will display a War Alert image on my website
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Button to retrieve and display an image?

Post by papa »

One way is to use a form and a type=button or type=submit and when the form is submitted you display the image.

if(isset($_POST['button_var'])) echo "<img ...>":
boondox
Forum Newbie
Posts: 20
Joined: Wed Oct 08, 2008 4:58 am

Re: Button to retrieve and display an image?

Post by boondox »

papa wrote:One way is to use a form and a type=button or type=submit and when the form is submitted you display the image.

if(isset($_POST['button_var'])) echo "<img ...>":


this would be helpful IF I knew how to write code...


I need the code already written though then I can just make the changes I need to make to fit it into my page..
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Button to retrieve and display an image?

Post by aceconcepts »

There a few ways you could do this. One very simple way would be to create a hidden field with the path and image name (including file type jpg or gif etc...), then create a submit button:

Code: Select all

 
//This is the form
<form method="post">//this form will POST to itself
<input type="hidden" name="strImage" value="path/image.jpg" />
<input type="submit" name="submitImage" value="Show Image" />
</form>
 

Code: Select all

 
//this is the "get image" part
if(isset($_POST['submitImage']))
{
$strImage=$_POST['strImage'];
}
 
echo'<img src="' . $strImage .'" />';
 
Does that make sense?
Post Reply