使用src加载php图像 [英] load a php image using src

查看:99
本文介绍了使用src加载php图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用以下方式加载图片:

Is it possible to load a image using:

<img src="image.php?image_id=1">

image.php

$image_id = $_GET['image_id']; 
echo "image".$image_id.".png"; 


推荐答案

您必须返回有效图片,使用 file_get_contents readfile 获取图像的内容然后输出到浏览器

you must return a valid image, use file_get_contents or readfile for get the conent of image then output to browser

 header("Content-Type:image/png");

    $image_id = $_GET['image_id']; 

    if(is_file($file = "image".$image_id.".png") ||  is_file($file = "no_image.png"))
        readfile($file); 

这篇关于使用src加载php图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆