|
Posted by J.O. Aho on 12/24/06 20:01
kenoli wrote:
> Actually, it did work. I was trying to retrieve a record that was
> empty for some reason. When I treid a different record, I got the
> image.
Good to hear you got it working.
> I am flying a bit here on blind faith, as I don't quite understand what
> is happening with the header() function. I surmise from what I've read
> that the header function says something like "On this page we will be
> outputting a png file."
Yes, you could easilly say that if you use
header("Content-type: image/png");
You could insert other info too, like how big the image is, if the image
should be cached (in this case it's the browser who decides, you give just a
recommendation).
> Then the browser (I presume it is the browser
> as what we are working with here is an http header) interprets the data
> sent via the echo statement as a png file.
Yes, the browser will match the content-type to an mime list and see what
action it should do, in most cases with images it's to display them inside the
HTML coded pages.
> Then, when we refer to the view.php script from the <img> tag, what is
> returned is the output of the echo statement in the view.php script
> interpreted as an image.
Yes, again and by the browser it's interpreted as any other png image, as say
mypicture.png had done in <img src="mypicture.png">.
> It is interesting to me that if I run the view.php script in a browser
> without including it in an <img> tag, nothing is sent to the browser.
This is for you don't supply an person_id to the script, I guess, you could
make the script a bit more advanced and if it detects that the person_id isn't
connected to an image in the database, then you can supply a default image.
Then if you try to access the view.php, you would see the default image.
> I don't even see the header information in the source code for that
> page. I think I still don't fully understand what is going on with
> these headers. It may be something I don't understand about http.
Header info are never displayed in a browser, it's just there to tell the
browser what to do. And this is a bit outside the HTML-code that you usually
write, this has to do with the http-protocol.
I hope this helps you to move forward in your understanding, I wish I knew how
to simply explain this, but it seems you have understood the basics.
--
//Aho
Navigation:
[Reply to this message]
|