我们有一些mp3文件集合和flash播放器使用此mp3文件,以跟踪mp3文件列表我们渲染mp3文件使用php文件下面是代码
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还是其他方式?
发布于 2011-05-29 23:28:05
(抱歉,我最初发帖时没有正确阅读问题-我现在看到问题出在IE和大文件大小上)
您可以尝试告诉IE长度,并刷新缓冲区:
header('Content-Length: ' . filesize($file));
ob_clean();
flush();发布于 2011-01-13 14:11:21
让Flash获取文件。通过PHP只将URL返回给Flash。
https://stackoverflow.com/questions/4677215
复制相似问题