【发布时间】: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=12 到http://www/example.com/files/xyz.mp3
所以用户可以轻松地直接下载 mp3 文件我如何防止这种情况?用php还是其他方式?
【问题讨论】:
-
即使使用您的第一个解决方案,用户也可以轻松下载文件。 对 URL 的请求会返回数据,无论您以何种方式对其进行切片。 可以保存此数据。这些数据如何在服务器端准确输出是无关紧要的。
-
不,您不能在不更改 URL 的情况下进行重定向。这就是重定向的定义:更改 URL。
标签: php flash .htaccess redirect mp3