Пример #1
0
        // file comment length
        $cdrec .= pack('v', 0);
        // disk number start
        $cdrec .= pack('v', 0);
        // internal file attributes
        $cdrec .= pack('V', 32);
        // external file attributes - 'archive' bit set
        $cdrec .= pack('V', $this->old_offset);
        // relative offset of local header
        $this->old_offset = $new_offset;
        $cdrec .= $name;
        // optional extra field, file comment goes here
        // save to central directory
        $this->ctrl_dir[] = $cdrec;
    }
    function filezip()
    {
        $data = implode('', $this->datasec);
        $ctrldir = implode('', $this->ctrl_dir);
        return $data . $ctrldir . $this->eof_ctrl_dir . pack('v', sizeof($this->ctrl_dir)) . pack('v', sizeof($this->ctrl_dir)) . pack('V', strlen($ctrldir)) . pack('V', strlen($data)) . "";
        // .zip file comment length
    }
}
$zip = new PHPZip();
$path = $_GET['path'];
$filename = $_GET['filename'];
if (isset($path) && isset($filename)) {
    $zip->createZip($path, $filename);
} else {
    echo "please input correct path and filename, like <a href=#>http://example.com?path=/home&filename=home.zip</a>";
}