通过PHP加载图像 [英] Loading an image through PHP

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

问题描述

我正在尝试通过PHP加载图像,但是我不知道如何. 文件名存储在数据库中,例如image.jpg

I'm trying to load an image through PHP, but I don't know how. The filename is stored in the database, such as image.jpg

if($_GET['image']){
    // Client requesting image, so retrieve it from DB
    $id = mysql_real_escape_string($_GET['image']);
    $sql = "SELECT * FROM $tbl_name WHERE id = '$id' LIMIT 1";
}

客户需要像这样请求图像

The client needs to request an image like so

http://example.com/index.php?image=1

然后它应该返回图像,因此可以像这样嵌入它:

And then it should return the image, so it can be embedded like this:

<img src="http://example.com/index.php?image=1" alt="" />

这可能吗?

推荐答案

$img = 'path/to/image.jpg';
header('Content-Type: image/jpeg');
readfile($img);

刚刚测试

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

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