静态 URL 中的随机视频

发布于 2024-09-25 17:37:53 字数 197 浏览 3 评论 0原文

我需要向客户端提供静态网址,例如。 http://domain.com/video.mp4。但是,每次访问此 URL 时,都需要从 5 个视频中选择一个随机视频。

使用 PHP 和 mod_rewrite 可以吗?或者其他方式?

谢谢

I need to provide a static url to a client, eg. http://domain.com/video.mp4. However this URL needs to provide a random video from a selection of 5 videos each time it is accessed.

Is this possible using PHP and mod_rewrite? Or some other way?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨曦慕雪 2024-10-02 17:37:53

也许能够提供 PHP 脚本的 URL (http://domain.com/video.php),然后该脚本将其 content-type 标头设置为视频类型,然后使用 readfile 随机读取文件。

我认为在这种情况下你不需要使用 mod_rewrite 。

header('Content-type: video/mp4'); // I don't know the correct MIME type
$files = array('vid1.mp4', 'vid2.mp4', 'vid3.mp4');
readfile($files[array_rand($files)]);

You may be able to provide a url to a PHP script (http://domain.com/video.php), which then sets its content-type header to the type of a video and then randomly reads out a file using readfile.

I don't think you need to use mod_rewrite in this case.

header('Content-type: video/mp4'); // I don't know the correct MIME type
$files = array('vid1.mp4', 'vid2.mp4', 'vid3.mp4');
readfile($files[array_rand($files)]);
微凉 2024-10-02 17:37:53

您的客户端是否要求 url 以 .mp4 结尾?

如果没有,您确实可以通过从 1 到 5 中选择一个随机数来使用 mod_rewrite

Does your client require the url to end in .mp4?

If not you could indeed use a mod_rewrite by selecting a random number from, say, 1 to 5

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文