【问题标题】:PHP redirect without change current url?PHP重定向而不更改当前网址?
【发布时间】:2011-01-13 05:53:57
【问题描述】:

我们有一些 mp3 文件集合和 flash 播放器使用这个 mp3 文件,为了跟踪 mp3 文件列表,我们使用 php 文件呈现 mp3 文件下面是代码

http://www/example.com/getFile.php?fileid=12

<?php
$id = $_REQUEST['fileid'];

// Some code to store download traking and get filename for this id in $filename var.
$filename = getFileName($id);

header('Content-type: audio/mpeg');
header('Content-Disposition: filename=' . $id . '.mp3');
readfile($filename);

?>

但 mp3 文件很大,播放器在 IE 中会崩溃,为此我们也使用下面的代码

<?php
$id = $_REQUEST['fileid'];

// Some code to store download traking and get filename for this id in $filename var.
$filename = getFileName($id);

header('Location: '. $filename);
?>

这段代码工作正常,但它也改变了当前的 URL 即http://www/example.com/getFile.php?fileid=12http://www/example.com/files/xyz.mp3

所以用户可以轻松地直接下载 mp3 文件我如何防止这种情况?用php还是其他方式?

【问题讨论】:

  • 即使使用您的第一个解决方案,用户也可以轻松下载文件。 对 URL 的请求会返回数据,无论您以何种方式对其进行切片。 可以保存此数据。这些数据如何在服务器端准确输出是无关紧要的。
  • 不,您不能在不更改 URL 的情况下进行重定向。这就是重定向的定义:更改 URL。

标签: php flash .htaccess redirect mp3


【解决方案1】:

让 Flash 获取文件。通过 PHP 只返回到 Flash 的 URL。

【讨论】:

    【解决方案2】:

    (抱歉,我最初发布时没有正确阅读问题 - 我现在看到问题出在 IE 和大文件大小)

    您可以尝试告诉 IE 长度,然后刷新缓冲区:

    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    

    【讨论】:

      猜你喜欢
      • 2013-11-09
      • 2012-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-21
      • 2013-09-09
      • 1970-01-01
      • 2013-06-11
      相关资源
      最近更新 更多