此代碼強制在Chrome和Mozilla上爲我下載。但問題是所有文件大小都是3kb。爲什麼?大小是不同的像3MB,4MB,3.5MB和下載文件只是一個腐敗的3kb ...請幫助。所有Mp3文件僅以3kb下載並損壞
注意:如果使用標題重定向,它可以在Chrome中正常下載或在其他瀏覽器中打開並在不下載的情況下開始播放。
<?php
//Bring in My functions
require_once ('../inc/functions.php');
//Bring in my header
require_once ('../inc/header.php');
?>
<!-- Page body starts -->
<div class="container">
<div class="col-md-9 contentArea">
<?php
//Get File, Check For Existence and Download
//Get File, Check For Existence and Download
if(isset($_GET['file'])){
$file = sanitizeMySQL($con, $_GET['file']);
$checkFile = "SELECT * FROM files WHERE f_song = '$file' AND f_del='0'";
$checkFileRun = mysqli_query($con, $checkFile);
$fileName = mysqli_fetch_assoc($checkFileRun);
//$song = $fileName['f_song'];
if($fileName['f_song']==null || $fileName['f_song'] == ""){
echo '<h4 class="text-center"><i class="fa fa-times-circle fa-3x red"></i><br />Sorry! This is does not Exist on this Server or has been moved</h4>';
}else{
$updateDownload = "UPDATE b_files SET f_count={$fileName['f_count']}+1 WHERE f_song ='$file' AND f_del='0'";
$updateDownloadRun = mysqli_query($con, $updateDownload);
$filePath = SITE_URL."music/".$file;
$fileSize = filesize($filePath);
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Length: ".$fileSize);
header("Content-Disposition: attachment; filename=".$file);
header("Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3");
header("Content-Transfer-Encoding: binary");
//Read the file
readfile($filePath);
//header("Location:".SITE_URL.'music/'.urldecode($fileName['file_song_name']));
exit();
}
}elseif(!isset($_GET['file'])){
echo '<h4 class="text-center"><i class="fa fa-times-circle fa-3x red"></i><br />Sorry! File Not Found</h4>';
}
//File Download Ends
?>
</div>
<!-- Call In The SideBar -->
<?php require_once '../inc/sidebar.php'; ?>
</div>
<?php
require_once ('../inc/footer.php');
?>
使用完整的本地路徑'/路徑//mp3'的,而不是''中的文件路徑$ = SITE_URL SITE_URL'。「音樂/".$ file' –
這並沒有解決問題。我已經嘗試過101%的確定。 'SITE_URL。「music /」.$ file'和'/ path/to/my/mp3'仍然是相同的輸出 –
在代碼編輯器中打開mp3文件。錯誤信息應該在你的3kb mp3文件中。 – vishva8kumara