Hi,
This is a very known problem with lot of solutions in many forums but none of them works for me.
A simple code to load a jpeg image as follows:

<html>
<?php
$im = @imagecreatefromjpeg("/home/public_html/MyPic.jpg");
header ("Content-Type: image/jpeg");
imagejpeg($im, NULL, 75);
imagedestroy($im);
?>
<head>
<title>
My First PHP Page
</title>
</head>
<body>
<FORM><INPUT TYPE="button" VALUE="Back"> </FORM>
</body>
</html>

The error message is as follows:
Warning: Cannot modify header information - headers already sent by (output started at /home/public_html/test.php:2) in /home/public_html/test.php on line 4

I have tried with the possible options below:
1. adding ob_start() and ob_flush() at the beginning and end
2. Saving in a notepad with ANSI encoding
3. Removing white-spaces/new-lines before/after php-tags/start-end-of-files/header()
None of them works.

But if I remove the <html> tag (Line:1) at the end of PHP code i.e. after ?> and before <head> then the error goes off and the image is rendered on the screen but all the following html code for title and button in <form> is not having any effect.
I am wondering why the <html> is not recognized and how to design user interaction with clickable buttons at the client-end to perform some image editing operations at the server-end.

Thanks!

Member Avatar for diafol

Place <html> after the header().

BUT if this is output as an image, why are you putting html into it?

Thanks for the reply!
Placing <html> after the header() works and I have already tested but the html portion of the code is not taking into effect such as the <title> is not working nor anything.
Are <html> tags not processed in *.php files ?

I want some user interaction at the client-end, i.e. suppose user clicks a button and some image operations are required to be performed at the server-end.
For recording user interaction like a clickable button, I do require html otherwise, how to achieve this in an easy fashion.
I have read somewhere that JavaScript and Ajax is required to record and pass the user-interaction commands from the client-end to PHP at the server-end.
But, how can this be achieved easily ?

Member Avatar for diafol

This file is for creating an image. SO why are you creating a html page out of it as well? Doesn't make sense to me. Either it's an image or it's a html snippet - it can't be both.

Can someone help me?

How to design a php page with an image and a user-clickable button which will trigger a different php function in a simple fashion!
The code in my first post runs through some error as described.

Thanks!

Can someone help me?

How to design a php page with an image and a user-clickable button which will trigger a different php function in a simple fashion!
The code in my first post runs through some error as described.

Thanks!

Honestly it sounds like you need to do more research on the language before you continue on. I would reccomend this book:
http://www.amazon.com/MySQL-Dynamic-Sites-Fourth-ebook/dp/B005GXM63U/ref=sr_1_2?ie=UTF8&qid=1328306153&sr=8-2

I have read both this book and his advanced PHP book and they are fantastic.

Member Avatar for diafol

Can someone help me?

How to design a php page with an image and a user-clickable button which will trigger a different php function in a simple fashion!
The code in my first post runs through some error as described.

Thanks!

This is a different question?
As mentioned, I think you need to do more research.

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.