|
发表于 2024-11-1 22:16:42
|
显示全部楼层
都不是我的
在线看XJJ 在这里下
https://hostloc.com/forum.php?mo ... =%E5%BC%80%E6%BA%90
随机图片
index.php
-----------------------------------------------------------------------
get_image.php
- <?php
- error_reporting(E_ALL);
- ini_set('display_errors', 1);
- function getRandomImage() {
- $imageDir = __DIR__ . '/pic/'; // 使用绝对路径
- $images = glob($imageDir . '*.{gif,jpg,png,avif,heic,heif,webp,jpeg}', GLOB_BRACE);
-
- if (empty($images)) {
- error_log("No images found in directory: $imageDir");
- return null;
- }
-
- return $images[array_rand($images)];
- }
- $image = getRandomImage();
- if ($image && file_exists($image)) {
- $imageInfo = getimagesize($image);
- if ($imageInfo) {
- header("Content-type: {$imageInfo['mime']}");
- readfile($image);
- } else {
- error_log("Failed to get image info for: $image");
- header("HTTP/1.0 500 Internal Server Error");
- echo "Error processing image";
- }
- } else {
- error_log("Image not found: $image");
- header("HTTP/1.0 404 Not Found");
- echo "Image not found";
- }
- exit;
- ?>
复制代码
|
|