i'm trying to make a download site to my watch online site i need the download site turns the videos into zip files before download it to the user then delete it, but some times when i click on the download button the whole computer freezes and it need to force shutdown to turn off , and some times it kind of work but it makes at least 5 to 8 zip files and delete it except 1 , this is my zip.php file (downloading file)
<?php
$type = isset($_GET['type']) ? filter_var($_GET['type'], FILTER_SANITIZE_STRING) : '';
if ($type = 'zip') {
include '../inc/config.php';
$series = filter_var($_GET['series'], FILTER_SANITIZE_NUMBER_INT);
$episode = filter_var($_GET['episode'], FILTER_SANITIZE_NUMBER_INT);
$get_series_name = $db->prepare('SELECT name FROM serieses WHERE ID = ?');
$get_series_name->execute(array($series));
$seriesInfo = $get_series_name->fetch();
$file_path = 'C:/xampp/htdocs/AnimeSite/Serieses/'. $seriesInfo['name'] .'/'. $episode .'.mp4';
$zip_name = $seriesInfo['name'] .' - Ep '. $episode . '.zip';
$zip = new ZipArchive;
$res = $zip->open($zip_name, ZipArchive::CREATE);
if ($res === TRUE) {
$zip->addFile($file_path, $seriesInfo['name'].' - '. $episode .'.mp4');
$zip->close();
} else {
echo 'failed';
}
if(file_exists($zip_name)){
header('Content-Description: File Transfer');
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'. $zip_name .'"');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header("Content-length: ". filesize('C:\xampp\htdocs\DownloadSite\comp\\' . $zip_name) ."");
ob_clean();
flush();
readfile($zip_name);
sleep(20);
unlink('C:\xampp\htdocs\DownloadSite\comp\\' . $zip_name);
}
?>
<div id="thank-msg">
<p>
<i class="fa fa-check-circle-o" aria-hidden="true"></i> Downloading ...
</p>
</div>
<?php
} else {
header('Location: ../index.php');
exit();
}
?>