Does html can be use with dynamic generated images in php?

时光毁灭记忆、已成空白 提交于 2019-12-01 21:57:19

Basically, to create dynamic image in HTML, you will need 2 PHP files:

  1. one for the image itself
  2. another one for PHP to display it.

Let's take a look how to do it:

  1. You create image.php that accept parameter, like: image ID or file name. For security reason, you HAVE to filter whatever parameter it get.

    Why you have to do this? because, to generate image, you can't mix it with another HTML output. Let alone a single space or return as this will render the image broken.

  2. You do the HTML thing on another PHP, say test92.php. To the HTML logic here, like:

    1. get image data
    2. loop the data
    3. display image => <img src="image.php?imageID=12" alt="" />

If you want a div around your image you have to do that in the html, you can't do that in the image generation code

<div>
<img src="http://localhost/php/test92.php">
</div>

If you are getting errors regarding the image, try browsing the image url http://localhost/php/test92.php and see what it looks like.

Does it show an image like you are expecting?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!