防止 Opera 表单缓存 mp3

发布于 2024-09-15 08:35:11 字数 824 浏览 5 评论 0原文

我再次尝试阻止从我的网站缓存 mp3 文件。我使用 flash 播放器,所有文件都在公共 html 之外,我使用这个脚本来访问文件

<?php

$file = $_GET['file'] . '.mp3';
 $fileDir = '/path/outside/public_html/';

if (file_exists($fileDir . $file))
{
    ob_start();

    $contents = file_get_contents($fileDir . $file);

    echo $contents;

    $buffer = ob_get_contents();

    ob_end_flush();

    header('Expires: Mon, 26 Jul 1980 00:00:00 GMT');
    header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
    header('Cache-Control: post-check=0, precheck=0', false);
    header('Pragma: no-cache');
    header('Content-type: audio/mpeg');

    echo $buffer;

} ?>

,我是 php noob,所以这个脚本可能有错误,但它可以工作...几乎,我在阻止 Opera 中的文件缓存时遇到问题 - 它仍然缓存 mp3 文件。我看到了一些解决方案:当我从网站播放文件时,文件被下载到缓存,但完整下载后文件被自动删除。没有时间复制此文件。所以我的问题是:怎么做?这可以用 php 实现吗?

again i try to prevent form caching mp3 files form my site. I use flash player, all files are outside public html i use this script to access to files

<?php

$file = $_GET['file'] . '.mp3';
 $fileDir = '/path/outside/public_html/';

if (file_exists($fileDir . $file))
{
    ob_start();

    $contents = file_get_contents($fileDir . $file);

    echo $contents;

    $buffer = ob_get_contents();

    ob_end_flush();

    header('Expires: Mon, 26 Jul 1980 00:00:00 GMT');
    header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
    header('Cache-Control: post-check=0, precheck=0', false);
    header('Pragma: no-cache');
    header('Content-type: audio/mpeg');

    echo $buffer;

} ?>

I'm php noob so this script is probably buggy, but it's work... Almost, i have problem to prevent file cache in Opera - it still cache mp3 files. I saw some solution: when i play files from site, file was downloaded to cache but after full download file was automaticly delete. There is no time to copy this file. So my question is: ho do this ? Is this possible with php?

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

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

发布评论

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

评论(1

只是偏爱你 2024-09-22 08:35:11

此问题可能是由服务器本身引起的,为了防止文件缓存,请尝试在文件名中添加一些额外的参数,例如:

$file = $_GET['file'] . '.mp3?' . time();

This issue can be caused by server itself, to prevent file caching try to add some extra parameter to file name like:

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