I want to create a button on a php pafe like a form now after pressing this button i should load an image. Now the I have done this. when the image is appearing it's on the other page than where the button was. I want to have the button on the same page. Left hand side i have a set of buttons and pressing each button should load image on the right side of the same page. I should be able to see the button and image both. Please help me how can I achieve this. Is it possible using only php. ?? Thanks for any help.

<?php

if(isset($_POST['submit']))
{

$imagepath="shirt7.jpg";

$image=imagecreatefromjpeg($imagepath);

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

imagejpeg($image);

}
?>
&lt;form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
   &lt;input type="submit" name="submit" value="Submit Form"><br>
&lt;/form>

Recommended Answers

All 4 Replies

It is possible if, instead of outputting the image, you output an image tag:

if (isset($_POST['submit']))
{
  $imagepath = "shirt7.jpg";
  echo "<img src="$imagepath" />";
}

it's giving error.

Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in C:\Server\Apache2\htdocs\phpbutton2.php on line 5

Now it's coming the '$imagepath' should be single quote. Thanks for your help friend.
echo "<img src='$imagepath' />";

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.