修复随机一言部分环境报错

This commit is contained in:
LyLme 2023-12-20 00:48:12 +08:00
parent 601accf7a7
commit dd42385b21

View File

@ -212,6 +212,9 @@ function get_real_ip()
function yan() function yan()
{ {
$filename = ROOT . '/assets/data/data.dat'; $filename = ROOT . '/assets/data/data.dat';
if (!file_exists($filename) || !is_readable($filename)) {
die(' 一言数据文件不存在或不可读');
}
$data = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $data = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
// 随机获取一行索引 // 随机获取一行索引
$result = $data[array_rand($data)]; $result = $data[array_rand($data)];