php zip冻结计算机并生成许多zip文件

时间:2017-08-30 12:21:17

标签: php download zip freeze ziparchive

我试图在我的手表在线网站上建立一个下载网站 我需要下载网站将视频转换为zip文件,然后将其下载到用户然后将其删除,但有时当我点击下载按钮时,整个计算机冻结,需要强制关机关闭,有时它很友好工作,但它至少产生5到8个zip文件并删除它,除了1, 这是我的zip.php文件(下载文件)

<?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();
}
?>

0 个答案:

没有答案