我的网站使用bookmarklet从外部网站收集数据,有点像Pinterest。我关心安全性,并希望将bookmarklet从文档根目录收集的图像上移一个级别。我的脚本有一些严格的安全检查,但我想添加这一点作为最后一道防线。
如何在脚本中访问我的图像?显然,使用../userimages/id/image.jpg不会起作用。我使用的是Apache。
谢谢!
发布于 2011-12-08 17:01:27
代理镜像
您可以使用代理脚本来提供图像,如下例所示:
// open the file in a binary mode
$name = '../userimages/id/image.jpg';
$fp = fopen($name, 'rb');
// send the right headers
header("Content-Type: image/png");
header("Content-Length: " . filesize($name));
// you may like to set some cache headers here
// dump the picture and stop the script
fpassthru($fp);
exit;这个例子来自PHP manuals fpassthru() page。您可以将此脚本保存在服务器文档根目录/httpdocs文件夹中的某个位置。
“欺骗”图像的URL
要使PHP文件在用户/浏览器中显示为图像文件,最简单的方法是使用Apaches mod_rewrite。我通常使用如下的URL结构:
http://www.example.org/image-id/image.png其中image-id是该特定图像的唯一标识符。这样,文件就有了正确的图像扩展名,而不是.php。
https://stackoverflow.com/questions/8428101
复制相似问题