我有一个脚本,它根据通过 url 中的 GET 变量发送的 ID 获取 mp3 曲目的 url。然后该脚本会强制下载此 url。我遇到的问题是找不到轨道。
$url = $row['url'];
$file_name = $row['track_name'] .' - '. $row['artist_name'];
$path_parts = pathinfo($url); //get path info
$base_url = $path_parts['basename']; //only include mp3 track just incase path added in there
$file_path = '../uploads/' . $base_url;
if (file_exists($file_path)) {
header('Content-Description: File Transfer');
header('Content-Type: audio/mpeg');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"".$file_name."\"");
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file_path));
ob_clean();
flush();
readfile($file_path);
exit;
}
else {
echo 'File not found.';
echo '<br/>';
echo $file_path;
}
什么是显示是这样的;
File not found.
../uploads/demo_4.wav
我已经尝试将完整的 url 作为$file_path
,所以http://localhost/upload/ ...
但同样的事情发生了。
如果我直接输入 URL,文件就在那里,所以我不确定发生了什么。