php - htaccess 将 PHP 重写为 PNG,然后 PHP 文件旋转图像数组 - 在 PNG 重写中不起作用
问题描述
我有一个文件:
http://example.com/rotating/bg.php
我已经重写为http://example.com/rotating/bg.png
使用以下 .htaccess 代码:
RewriteRule \.png$ bg.php [L,NC]
在 bg.php 上,我有一个基本上在刷新时随机加载图像数组的代码,代码如下:
<?php
$imagesDir = 'img/';
$images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
$randomImage = $images[array_rand($images)]; // See comments
$file_out = $randomImage; // The image to return
if (file_exists($file_out)) {
$image_info = getimagesize($file_out);
//Set the content-type header as appropriate
header('Content-Type: ' . $image_info['mime']);
//Set the content-length header
header('Content-Length: ' . filesize($file_out));
//Write the image bytes to the client
readfile($file_out);
}
else { // Image file not found
header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
}?>
我希望 bg.png 的行为方式相同,并且还会重新加载图像,但是它会加载 1 张图像并且无论我刷新多少次都不会更改它。
我接近这个错误吗?任何帮助使它工作将不胜感激!
解决方案
推荐阅读
- android - 如何在单个请求中上传具有多个字符串参数的多个图像
- javascript - Array.push() 方法替换初始索引值而不是在末尾追加
- javascript - D3.js 使用 d3 append 将“rect”元素添加到 svg 时不可见的 rect 元素
- c++ - 仅具有向量的 MLP 和反向传播问题
- outlook - Microsoft Graph 安全警报获取 Internet 消息 ID
- php - Docker,如何在 PHP 中的另一个容器中获取容器 IP?
- postgresql - Knex 缓慢释放与池的连接
- android - Flutter Simulator Error While具有从firebase集合中获取值的下拉菜单
- python - 使用 MS Drive API 从 OneDrive 下载和上传文件
- javascript - 随机数组元素总是缺少元素 0