I started working on page for my school project today, and I find myself stucked. The HTML and PHP is quite simple, even if PHP I saw for first time, because it’s almost same as C. But the problem I got is about HTML meta tags and so on, specificaly the content-type. I want to generate image with php code which I already do with an ease, but when I want to display it that tag comes to game. I already came to conclusion that setting Content-Type tag with PHP is using last call to command like
header("Content-type:image/jpeg");
Now that I want to display my image, this tag has to be set as in the command, but then the whole page comes as image. On other hand with setting text/html, image displays as text. Is it possible to dynamicaly change that element in one file? I doubt, because only one head specification is possible at all, but I think there are guys much smarter then me with some work-arounds.
Everything I want to do now is generating image and displaying it where I want. I want to be able to parametrize that image also. I already created working solution with HTML tag <img src="img.php",x,y> ,where img.php is generating image, but it’s setting anyway Content-Type to image and it’s just whole way around, as how to get 2 head specifications. Also I can’t set any parameters for this.
You can only commit one
Content-Typeper response. You can respond with an image or you can respond with a page, but not both. They must be two separate HTTP requests.One way to solve this is to have your img.php script serve the image (as it sounds like it already is), and then a different script which serves your HTML. The HTML it serves will reference the img.php script, such as: