下载.tar会导致循环

时间:2014-03-15 15:01:42

标签: php fopen tar

我正在尝试单击tar目录并提示下载tar.gz.我有另一个页面,我选择tar目录,但现在当我下载它时,我无法打开它。它只是将.tar扩展为.cpgz然后再返回.tar并依次打开。

<?php
require_once('header.html');
ini_set('max_execution_time','0');

if (isset($_POST)) {
    $site = $_POST['site'][0];
    if(empty($site)) {
        echo("<p class=\"text-danger\"><strong>You didn't select anything to tar.</strong></p>");
    } else {
            $site_name = str_replace('.', '' , $site);
    $command = "/bin/tar --strip-components=2 -czvf /var/www/backup/" . date("ymd") . "_${site_name}.tar.gz /var/www/${site}";
            shell_exec($command);
            $pathtofile = "/var/www/backup/" . date("ymd") . "_${site_name}.tar.gz";
            $filename = date("ymd") . "_${site_name}.tar.gz";

            function promptToDownload($path, $browserFilename, $mimeType)
            {
                    if (!file_exists($path) || !is_readable($path)) {
                            return null;
                    }

                    header('Content-Description: File Transfer');
        header('Content-Type: application/x-gzip');
        header('Content-Disposition: attachment; filename="'.basename($browserFilename).'"');
        header('Content-Transfer-Encoding: binary');
        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($browserFilename));

                    $fp = fopen($path, "r");
                    fpassthru($fp);
            }

            promptToDownload($pathtofile, $filename, 'multipart/x-gzip');
    }
}

require_once('footer.html');

?>

有什么想法吗?

0 个答案:

没有答案