Jump to content

File Zipping using RecursiveIteratorIterator?


random1

Recommended Posts

Hi All,

 

I have the following code for zipping up a folder:

 

	ini_set('max_execution_time', 50000); // 50 seconds

	// create object
	$zip = new ZipArchive();

	// open archive 
	if ($zip->open($destinationpath, ZIPARCHIVE::CREATE) !== TRUE)
	{
		return 'Could not open archive ' . $destinationpath;
	}

	// initialize an iterator
	// pass it the directory to be processed
	$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folders));

	// iterate over the directory
	// add each file found to the archive
	foreach ($iterator as $key=>$value)
	{
		$zip->addFile(realpath($key), $key) or die ('ERROR: Could not add file: ' . $key);
	}

 

This code works fine for some directories but others trigger:

 

die ('ERROR: Could not add file: ' . $key);

 

I think the issue has to do with:

 

$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folders));

 

Is this way to do this? Is there an alternative?

Hmm... I found this:

 

http://us.php.net/manual/en/function.ziparchive-addfile.php

 

Comment at bottom by Andreas R. newsgroups2005 at geekmail de

 

Currently the number of files that can be added using addFile to the ZIP archive (until it is closed) is limited by file descriptors limit.

 

How can I take this into account in the code?

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.