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;
}
精彩评论