仅在PHP中满足条件时才提供图像文件

时间:2011-09-12 13:48:59

标签: php

我想通过HTTP提供图像,例如example.com/images.php?id=1234。但它受条件(登录,权限)等条件限制。如果条件为真,它会发送一个合适的标题数据体和图像数据。否则,将发送另一张图像的内容。

1 个答案:

答案 0 :(得分:3)

if(<your conditions>) {
    header("Content-Type: image/jpeg"); // or image/png, etc (depends on type)
    readfile("/path/to/conditions-met.jpg");
    exit;
} else {
    header("Content-Type: image/jpeg"); // or image/png, etc
    readfile("/path/to/conditions-failed.jpg");
    exit;
}