Well I don't know exactly what to tell you, have you tried removing the headers and adding error checking and output:
echo "<pre>";
$zip = new ZipArchive();
//Open a ZIP file archive 1
if( $zip->open('./user_'.$_SESSION['membername'].'/project.zip', ZipArchive::CREATE) ) {
echo "Zip created successfully\n";
} else {
die('Unable to create zip');
}
//add each file to archive
foreach ($files as $file)
{
$target=str_replace($base,'',$file);
//Adds a file to a ZIP archive from the given path
if( $zip->addFile($file, $target) ) {
echo "$file added as $target succesfully\n";
} else {
echo "$file was unable to be added\n";
}
}
//Close the active archive
if( $zip->close() ) {
echo "Succesfully close archive\n";
} else {
echo "Unable to close archive, errors may have occured\n";
}
echo '</pre>';
Doing that and then just outputting a link to the archive might be better for the time being until you get the zip created successfully.
Also here is a script I use to back up my websites, hopefully it can help you understand what I do to the filepath?
<?php
// Settings
$flags = array(
'FTP' => TRUE,
);
// Directory
$folderBlacklist = array('cgi-bin');
$dir = '/path/to/folder';
// FTP
$FTPHOST = '--';
$FTPUSER = '--';
$FTPPASS = '--';
/******************************\
**** Don't Edit Below HERE ***
\******************************/
// Initialize zip file
$zipname = date('Y-m-d').'_'.$_SERVER['SERVER_NAME'].'.zip';
if( file_exists($zipname) ) unlink($zipname);
$zip = new ZipArchive();
$zip->open($zipname,ZipArchive::CREATE);
addToZip($dir,$zip);
if( $zip->close() === FALSE ) {
print("\nArchive creation failed.\n");
} else {
print("\nArchive creation successful.\n");
}
if( $flags['FTP'] ) {
if( $ftp = ftp_connect($FTPHOST) ) {
if( ftp_login($ftp,$FTPUSER,$FTPPASS) ) {
ftp_pasv($ftp,TRUE);
if( ftp_put($ftp,$zipname,basename($zipname),FTP_BINARY) ) {
echo "\n\nFile Upload successful.";
unlink($zipname);
} else {
echo "\n\nFile Upload failed.";
}
} else {
echo "\n\nFTP login failed.";
}
ftp_close($ftp);
} else {
echo "\n\nFTP connection failed.";
}
}
function addToZip($path,ZipArchive $zip) {
static $depth = 0;
static $root;
if( $depth == 0 && is_dir($path) ) {
$root = realpath($path) . DIRECTORY_SEPARATOR;
$depth++;
}
if( is_file($path) ) {
$file = str_replace($root,'',$path);
if( $zip->addFile($path,$file) ) {
echo "Added $path as $file\n";
} else {
echo "FAILED $path\n";
}
} elseif( is_dir($path) ) {
echo "\nAdding folder: $path\n";
$dir = realpath($path) . DIRECTORY_SEPARATOR;
$dir = glob($dir.'*');
array_walk($dir,'filterGlob');
$dir = array_filter($dir);
usort($dir,'sortGlob');
foreach( $dir as $sub ) {
addToZip($sub,$zip);
}
} else {
return FALSE;
}
}
function sortGlob($a,$b) {
if( is_dir($a) && is_file($b) ) return -1;
if( is_file($a) && is_dir($b) ) return 1;
return strcasecmp($a,$b);
}
function filterGlob(&$path,$key) {
GLOBAL $folderBlacklist;
if( in_array(basename($path),$folderBlacklist) )
$path = FALSE;
}