Все Mp3 файлы, загруженные только с 3kb и поврежденные

Этот код принудительно загружает меня как на Chrome, так и на Mozilla. Но проблема в том, что все файлы имеют размер 3 КБ. Зачем? Размеры разные, как 3 МБ, 4 МБ, 3,5 МБ, а загружаемый файл просто поврежден 3 КБ … Пожалуйста, помогите, пожалуйста.

Замечания: Если используется перенаправление заголовка, он нормально загружается в 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');
?>

0

Решение

Когда вы выполняете чтение файла, вы уже записали включенные файлы и немного HTML в выходной буфер. Это приведет к повреждению медиа-файла. Возможно, вы захотите поместить readfile и выйти (или die ()) перед выходом любого содержимого HTML.

И SITE_URL не будет работать для $ filePath. Возможно, вам придется найти правильный путь к файлу, добавив

...dirname(dirname(__file__))...
0

Другие решения

Спасибо Vishva8kumara. У меня есть все выходные данные, и он загружается с нулевым байтом и файл поврежден. Ниже новый код

   <?php
//Bring in My functions
require_once ('../inc/functions.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 = "http://localhost/du/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();
}
}
?>
0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector