Hi All,
I am trying to generate and send a Captcha directely to the Browser using imagejpeg() in a php script but it is not working. If I send the image to a file it works fine !
I am using the following script:
imagecreate();
......
header('Content-Type: image/jpeg');
imagejpeg($image);
<img src="captcha.php?width=100&height=40&characters=5"/> // I call the php script using <img/> tag from a html form...
As I mentioned before if I use all the code exactly as it is but I send the image to a file using: imagejpeg($image, file); It Works perfectly...
Any hint will be highly appreciated !
Thanks !
El Vasco
imagejpeg() not sending output to the browser
Moderator: General Moderators
- greyhoundcode
- Forum Regular
- Posts: 613
- Joined: Mon Feb 11, 2008 4:22 am
Re: imagejpeg() not sending output to the browser
Without seeing a more complete excerpt of your code it is difficult to say.
As a guess the problem could be that the headers have already been sent (this could happen if you have inadvertently "leaked" some whitespace or otherwise output some text). You could test for this as follows:
As a guess the problem could be that the headers have already been sent (this could happen if you have inadvertently "leaked" some whitespace or otherwise output some text). You could test for this as follows:
Code: Select all
if (headers_sent())
{
exit('Wooops! Cannot send anymore headers.');
}
else
{
header('Content-Type: image/jpeg');
imagejpeg($image);
}Re: imagejpeg() not sending output to the browser
Hi greyhoundcode !
Thanks for your piece of advice !
Now it is working but unfortunately I did more than one change at the same time and now I cannot know exactly what was the problem
....
Anyway, among the changes I did I found I had a double << sign in the php tag : I had <<?php instead of <?php so I believe that was the mistake...
Thanks for your help !
El Vasco
Thanks for your piece of advice !
Now it is working but unfortunately I did more than one change at the same time and now I cannot know exactly what was the problem
Anyway, among the changes I did I found I had a double << sign in the php tag : I had <<?php instead of <?php so I believe that was the mistake...
Thanks for your help !
El Vasco
- greyhoundcode
- Forum Regular
- Posts: 613
- Joined: Mon Feb 11, 2008 4:22 am
Re: imagejpeg() not sending output to the browser
Happy to help.
Certainly if you opened with <<?php then the headers would already have been sent, they cannot of course be sent more than once.
Certainly if you opened with <<?php then the headers would already have been sent, they cannot of course be sent more than once.