How can I use multiple PHP header content types on the same page? is this possible?
You can't. But what you can do is something like this in your HTML:
<img src="my_img.php" />
Of course my_img.php
would be a PHP file that has a header("Content-type: image/jpeg");
line, and outputs your image.
Can I use multiple Content-type's on same page?
No, you can only have one Content-Type
per page.
What you should do is simply create another page, that contains both an image (with src pointing to the code you showed) and the form you want to display, like this:
<html>
<body>
<div>
<img src="image.php" alt="image retreived from DB" />
</div>
<form>
<input type="text" name="foo" />
...
</form>
</body>
</html>
How can I pass multiple file extensions parameter in header?
If you want in downloading any type of file you can just use application/octet-stream.
header('Content-Type: application/octet-stream');
// for example this will download any type of file
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
Does the HTTP Protocol support multiple content types in response headers?
You need to look at the definition of the header field:
http://greenbytes.de/tech/webdav/rfc2616.html#rfc.section.14.17
Content-Type = "Content-Type" ":" media-type
so it takes a single media-type, which is defined by the grammar you quoted above.
So the answer is: a single type/subtype, followed by optional parameters.
PHP header, Content type: image not allowing text
You need to make a separate PHP script which serves the image, then make an <img>
tag that points to this script.
You can send information to the script using the querystring in the image URL.
outputting image content type using two functions
The final content you send to the client can have one content-type only. Either image or text. If you want both in a single page, (when image isn't written to file) you could write the image in base64 in the following way:
data:[<MIME-type>][;charset=<encoding>][;base64],<data>
In your case,
data:image/gif;base64,<base64_encoded_image>
See Data URI scheme
Something like the following will work: (Untested)
$img = fread(fopen($path, "r"), filesize($path));
$base64 = "data:image/gif;base64," . base64_encode($img);
Related Topics
PHP Remove/Fix Module Not Found or Already Loaded Warnings
PHP Post Limited to 1000 Variables
Wherejsoncontains Laravel 5.6 Not Working
Firefox Error 'No Element Found'
How to Get Order Id in Woocommerce_Email_Headers Hook
PHP - Find If an Array Contains an Element
PHP Associative Array Key Order (Not Sort)
Class App\Http\Controllers\Usercontroller Does Not Exist
Using Ajax/Jquery to Refresh an Image
How to Resolve the Error: SQL Authentication Method Unknown in Laravel-Mysql
How to Get the Columns Names Along with Resultset in PHP/Mysql
How to Store Variable Values Over Multiple Page Loads
PHP - Upload Picture and Display on Page
Regular Expression to Remove CSS Comments
Unable to Scrape Content from a Website
How to Format a PHP Include() Absolute (Rather Than Relative) Path