0

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_pathhttp://localhost/upload/ ...が、同じことが起こります。

URL を直接入力すると、ファイルがそこにあるので、何が起こっているのか正確にはわかりません。

4

2 に答える 2