in reply to Displaying randomly created png's in HTML

Explaining how HTTP works might give you better understanding.

Basically a browser fetches a page (for arguments sake call it page.html) with a GET request (webserver sends as content-type text/html). It then analyzes the file for IMG tags, EMBED tags, background tags in TABLE and BODY, etc and it converts those relative filenames into full URLs (if relative filenames are used). Then it fetches those files one by one and inserts em into the page. Text browsers like Lynx (which is libwww based, like LWP::Simple etc) don't automagically fetch all files . They don't display images, play soundfiles or shockwave animations.

Bottom line is that your images are treated as images, thru the HTTP header the webserver sends, same header that is generated by your script. If your script doesn't generate a content-type header (or a invalid one for the data), the webserver doesn't know what content-type it is and neither does your browser. Regular files have valid content-type headers since that's directly handled by the webserver.

There is a request for each file that needs to be downloaded. So you can't insert HTML tags in image/png data, since the HTML page was handled in a previous request (as content-type text/html). You can't mix different content-types in the same script call. Once the HTTP header is set, the remaining data is handled as belonging to that specific content-type data.

Hope this makes sense... This is only part of the HTTP protocol, things will get clearer once you're used to the basic stuff.

Note: There are ofcourse POST requests, but that's a whole new chapter.

If you want to know more about HTTP, you can check RFC 2616, which are the specs for HTTP 1.1 (1.0 is still more commonly used but it'll give ya an idea). Ofcourse you can always just learn while you go, which is more fun.

Greetz
Beatnik
... Quidquid perl dictum sit, altum viditur.
  • Comment on Re: Displaying randomly created png's in HTML