【问题标题】:How to show image and content from the database to a PHP page?如何将数据库中的图像和内容显示到 PHP 页面?
【发布时间】:2014-11-08 02:22:59
【问题描述】:

我想使用 php 在页面上同时显示图像和内容。我可以通过设置 header(“Content-type: image/png”); 使用 php 仅向页面显示图像但无法与从数据库中获取的 html 内容一起显示。

感谢和问候

【问题讨论】:

  • 你不能在同一个响应中同时发送这两个,除非你将图像作为 data-uri 嵌入到 html 中
  • data-uri 为我工作。谢谢

标签: php cakephp phpmyadmin


【解决方案1】:

您不能在一个文件中包含相同的代码。您必须至少制作 2 个文件。一种用于创建图像,另一种用于显示 html。

image.php

<?php
header("Content-type: image/png");
// read a file or create it using GD below:
readfile("/path/to/image.png");

接下来你要制作你的html:

page.php

<p>
    <img src="image.php" alt="my image" />
</p>
<p>
    Here some HTML alongside my php image!
</p>

【讨论】:

  • 当两个东西都出现在同一个查询中并且我们必须将它们一起发送时,这将不起作用。但是使用 data-uri 我们可以做到这一点。
猜你喜欢
  • 2018-04-19
  • 1970-01-01
  • 2016-08-26
  • 1970-01-01
  • 2019-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多