php unzip no 1024 limit

Here, a simple script to unzip a .zip file in php without the 1024 characters limitations

function unzip($zip, $root, $target_folder = "") 
{
    $zip_file = zip_open($root . $zip);
    while ($zip = zip_read($zip_file))
    {
        $zip_object = zip_entry_name($zip);
        if (!is_dir(dirname($root . $target_folder . $zip_object))) 
        {
            mkdir(dirname($root . $target_folder . $zip_object), 0777, true);
        }
        $hedef_doc = $root . $target_folder . $zip_object;
        if(substr($hedef_doc, -1) != "/")
        {
            touch($hedef_doc);
            $target_file = fopen($hedef_doc, 'w');
            $size = 0;
            while($size < zip_entry_filesize($zip))
            {
                 fwrite($target_file, zip_entry_read($zip));
                 $size += 1024;
            }
     	     fclose($target_file);
        }
    }
    return true;
}

unzip("file.zip", "./", "target_directory");

Leave a Reply