Ejemplo n.º 1
0
/**
 * Implementation of hook_page.
 * Zip current file/folder 
 */
function ft_zip_page($act)
{
    global $ft;
    if ($act == 'zip') {
        $_REQUEST['file'] = trim(ft_stripslashes($_REQUEST['file']));
        // nom de fichier/repertoire
        $zip = new zipfile();
        if ($ft["plugins"]["zip"]["filebuffer"]) {
            $zip->setOutFile($ft["plugins"]["zip"]["filebuffer"]);
        }
        $substr_base = strlen(ft_get_dir()) + 1;
        foreach (ft_zip_getfiles(ft_get_dir() . '/' . $_REQUEST['file']) as $file) {
            $filename = substr($file, $substr_base);
            $filesize = filesize($file);
            if ($filesize > 0) {
                $fp = fopen($file, 'r');
                $content = fread($fp, $filesize);
                fclose($fp);
            } else {
                $content = '';
            }
            $zip->addfile($content, $filename);
        }
        if ($ft["plugins"]["zip"]["filebuffer"]) {
            $zip->finish();
            $filesize = filesize($ft["plugins"]["zip"]["filebuffer"]);
        } else {
            $archive = $zip->file();
            $filesize = strlen($archive);
        }
        header('Content-Type: application/x-zip');
        header('Content-Disposition: inline; filename="' . $_REQUEST['file'] . '.zip"');
        header('Content-Length: ' . $filesize);
        if ($ft["plugins"]["zip"]["filebuffer"]) {
            readfile($ft["plugins"]["zip"]["filebuffer"]);
            unlink($ft["plugins"]["zip"]["filebuffer"]);
        } else {
            echo $archive;
        }
        exit;
    }
}