开发者

Serving an image file only when a condition is met in PHP

I want to serve images over HTTP like example.com/images.php?id=1234 .But it is subject to conditions (logged in, permissions) etc开发者_开发百科. If the conditions are true, it would send an appropriate header with the data body and the image data. Else, the content of another image is sent.


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜