Jump to content

[SOLVED] zip


plutomed

Recommended Posts

i dont get how you use these functions to extract a zip file ???

 

A simple example, if the zip has a directory structure you will need to include that logic, this example only reads files!

 

<?php

// zip file to open and read

$zip_file = './path/name_of_file.zip';

// place to extract zip file to

$extract_to = './path_to_extract_to/';

// try to open the zip file

$zf = zip_open ( $zip_file ) or die ( 'FILE ERROR: can not open to unzip, ' . $zip_file . '!' );

// array container to hold the file names found in the zip file

$files = array ();

// keep reading until there is no files left to read

while ( $zs = zip_read ( $zf ) )
{
// do we have a valid file to read

if ( zip_entry_open ( $zf, $zs, 'rb' ) !== false )
{
	// read the complete file

           	$zo = zip_entry_read ( $zs, zip_entry_filesize ( $zs ) );

	// get the file name

	$fn = zip_entry_name ( $zs );

	// save the file to the extract directory

	$fs = fopen ( $extract_to . $fn, 'wb' );
	fputs ( $fs, $zo );
	fclose ( $fs );

	// add the file name to are information array

	$files[] = $extract_to . $fn;
}
}

// done, release the resource

zip_close ( $zf );

// just show the files in the zip file information array

echo '<pre>' . print_r ( $files ) . '</pre>';

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/38883-solved-zip/#findComment-187066
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.