显示私人目录中的图像 [英] Display images from private directory
本文介绍了显示私人目录中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些图像存储在无法通过URL访问的目录中(该目录不是公共目录)。
I have some images stored in a directory which is not accessible via the URL (the directory is not public).
如何在html中显示这些图像
How can I display those image in the html page using PHP?
推荐答案
理想情况下,您只是使该目录可访问,但是如果绝对不可能,则可以这样做:
Ideally you'd just make that directory accessible, but if that's absolutely not possible then you can do this:
myimage.php
myimage.php
$file = 'privatedir/image.jpg';
$type = 'image/jpeg';
header('Content-Type:'.$type);
header('Content-Length: ' . filesize($file));
readfile($file);
exit();
然后使用myimage.php作为img标签src。
Then use myimage.php as the img tag src.
这篇关于显示私人目录中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文