This code force downloads fine for me on both Chrome and Mozilla. But the issue is that all file size are 3kb. Why? The sizes are different like 3MB, 4MB, 3.5MB and the download file is just a corrupt 3kb... Kindly help please.
Note: If a use a header redirection, it downloads fine in Chrome or opens in other browsers and start playing without downloading.
<?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');
?>