Arvind GK
Arvind GK

Reputation: 27

I want to zip file under PHP 7.1.6,

I want to zip file under PHP 7.1.6 AME="openSUSE Leap" VERSION="42.2" PEAR Version: 1.10.1 PHP Version: 7.1.6 Zend Engine Version: 3.1.0 Running on: Linux linux-2ifi 4.4.70-18.9-default #1 SMP Wed May 31 09:09:25 UTC 2017 (c1231a7) x86_

I can only download empty zip files, not able to identify were things are wrong, can someone help me in this

I have a bunch of *.xml files, that needs to be zipped as xmlfiles.zip and download.

//ob_end_flush();

//$files = glob("*xml");
$files = array('*.xml');
//echo "<pre>";print_r($files);die;
if (is_array($files)) {
	// and proceed with your code
	$zipname = 'xmlfiles.zip';
	$zip = new ZipArchive;
	$zip->open($zipname, ZipArchive::CREATE);
	foreach ($files as $file) {
	  $zip->addFile($file);
	}
	$zip->close();
	header('Content-Type: application/zip');
	header('Content-disposition: attachment; filename='.$zipname);
	header('Content-Length: ' . filesize($zipname));
	readfile($zipname);
 
}

Upvotes: 1

Views: 293

Answers (1)

Vishal Roy
Vishal Roy

Reputation: 130

$files = array("*xml"); line is trying to find a particular *.xml file and not all the xml files in the directory

Okay so uncomment the line

$files = glob("*.xml");

and comment

$files = array("*.xml");

The glob() function returns an array of filenames or directories matching a specified pattern.

Upvotes: 1

Related Questions