Jump to content

php create zip-file error..


Alkimuz

Recommended Posts

Hey,

 

i'd like to extract filenames from my database and present them as a downloadable zip-file to my users. I found a usefull function on http://davidwalsh.name/create-zip-php and thought i could work that out to my needs, but on this function itself (before using it), i get an error..

 

on the following line:

if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {

 

i get: Parse error: syntax error, unexpected ')', expecting '('

 

i dont get it, dont think there is actually an error in the function.. does it mean that the php installed on the server i use, cant handle this function or anything?

 

my phpinfo: http://dwarsfluit.davidvandiepen.nl/test.php

 

the function is:

 

<?php
/* creates a compressed zip file */
function create_zip($files = array(),$destination = '',$overwrite = false) {
//if the zip file already exists and overwrite is false, return false
if(file_exists($destination) && !$overwrite) { return false; }
//vars
$valid_files = array();
//if files were passed in...
if(is_array($files)) {
	//cycle through each file
	foreach($files as $file) {
		//make sure the file exists
		if(file_exists($file)) {
			$valid_files[] = $file;
		}
	}
}
//if we have good files...
if(count($valid_files)) {
	//create the archive
	$zip = new ZipArchive();
	if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
		return false;
	}
	//add the files
	foreach($valid_files as $file) {
		$zip->addFile($file,$file);
	}
	//debug
	//echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;

	//close the zip -- done!
	$zip->close();

	//check to make sure the file exists
	return file_exists($destination);
}
else
{
	return false;
}
}?>

 

thanks for helping!

Link to comment
https://forums.phpfreaks.com/topic/255250-php-create-zip-file-error/
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.