【发布时间】:2015-11-13 16:11:31
【问题描述】:
我目前正在尝试在我的服务器上运行一个小脚本,重点是在某个地址提供随机 PNG,例如 https://domain.me/image/。
在 /image/ 中,我有这个 index.php,它可以很好地完成工作并输出我想要的内容:
<?php
$max = 30;
$image = rand(1, $max);
$name = '/var/www/image/src/'.$image.'.png';
$fp = fopen($name, 'rb');
header("Content-Type: image/png");
header("Content-Length: " . filesize($name));
fpassthru($fp);
exit;
?>
(我的 PNG 和你猜的一样存储在 /image/src/ 中)
当有人调用 https://domain.me/image/script.png 时,我现在正尝试运行该脚本(有些网站需要在 URL 末尾添加 PNG 扩展名),但我真的不知道如何继续。
【问题讨论】: