如何在同一页面上使用多个 PHP 标头内容类型?这可能吗?

2022-01-11 00:00:00 header content-type php

是否可以在一个文档中使用多种标题类型?例如:

Is it possible to use multiple header types in one document? For example:

header("Content-type: image/jpeg");
header('Content-Type: text/html; charset=utf-8');

将整个页面返回为 text/html... 而

returns the whole page as text/html... while

header('Content-Type: text/html; charset=utf-8');
header("Content-type: image/jpeg");

将整个页面作为图像返回.... 如何在同一页面上使用两种类型的内容?我在顶部使用 ob_start(),在开头使用 ob_end_flush().

Returns the whole page as an image.... How can I use both types of content on the same page? I'm using ob_start() at the top and ob_end_flush() at the beginning.

推荐答案

你不能.但是你可以在你的 HTML 中做这样的事情:

You can't. But what you can do is something like this in your HTML:

<img src="my_img.php" />

当然 my_img.php 是一个 PHP 文件,它有一个 header("Content-type: image/jpeg"); 行,并输出您的图像.

Of course my_img.php would be a PHP file that has a header("Content-type: image/jpeg"); line, and outputs your image.

相关文章