25 lines
837 B
PHP
25 lines
837 B
PHP
<?php
|
|
// 路径计算
|
|
$filenames = $stmt->fetchAll(PDO::FETCH_COLUMN, 0); // 从数据库取出的文件名
|
|
$random_filename = $filenames[array_rand($filenames)]; // 随机一个文件名
|
|
$push_path = $base_img_path . $random_filename; // 相对路径
|
|
$imageUrl = $baseURL . $push_path; // URL
|
|
|
|
// 返还数据
|
|
if (empty($mode)) {
|
|
header('Content-Type: image/jpeg');
|
|
header('Content-Length: ' . filesize($push_path));
|
|
readfile($push_path);
|
|
exit;
|
|
} elseif ($mode == 'json') {
|
|
header('Content-Type: application/json');
|
|
echo json_encode(['code' => 200, 'image_url' => $imageUrl, 'endpoint_type' => $et, 'time' => $time, 'is_source' => $source, 'mode' => 'json']);
|
|
exit;
|
|
} elseif ($mode == 'redirect') {
|
|
header('Location: ' . $imageUrl);
|
|
exit;
|
|
} else {
|
|
header('Location: ' . $imageUrl);
|
|
exit;
|
|
}
|
|
?>
|