PHP 获取远程目录下所有 MP4 视频
由于 PHP 无法直接读取远程文件夹的内容,需要使用其他方法。以下是一种可能的解决方案:
require "./function.php"; // 引入函数文件
addApiAccess(1); // 调用统计函数
$dir_url = 'http://av.host.gay/mp4/aaaa/'; // 目录URL
$dir_content = file_get_contents($dir_url); // 获取目录页面内容
preg_match_all('/<a href=\'([^\']+\.mp4)\'>/', $dir_content, $matches); // 使用正则表达式匹配所有mp4文件链接
$mp4_array = $matches[1]; // 获取链接数组
$mp4 = array_rand($mp4_array); // 随机选择一个链接
header("location:$dir_url$mp4_array[$mp4]"); // 跳转到选择的链接
这个脚本首先使用 file_get_contents 函数获取目录页面的 HTML 内容,然后使用正则表达式匹配所有 MP4 文件的链接,将链接保存在数组中。然后从数组中随机选择一个链接,并使用 header 函数将用户重定向到该链接。注意,这种方法可能会受到远程服务器防火墙等安全限制,无法正常工作。
原文地址: https://www.cveoy.top/t/topic/np9s 著作权归作者所有。请勿转载和采集!