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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.