[?] PHP ZipArchive... - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: [?] PHP ZipArchive... (/showthread.php?tid=95892)
[?] PHP ZipArchive... by whiz on 11-21-2010 at 03:25 PM
I'm trying to use the PHP ZipArchive class, but I can't seem to get it to work. It always has a status of 0, and the folder is never created. The script is uploaded here.
php code: print("<pre>Result of file system search:\n\n");
print_r(glob("{level,scenario}s/*/*.mf{l,s}", GLOB_BRACE));
print("\nOpening archive...\n");
$zip = new ZipArchive();
$zip -> open("files.zip", ZIPARCHIVE::CREATE) or die("Error: could not open archive.");
print("\nLoading levels through iterator...\n");
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("levels/"));
foreach ($iterator as $key => $value)
{
print("| ".$key." => ".$value."\n");
$zip -> addFile(realpath($key), $key) or die ("Error: could not add file: ".$key);
}
print("\nLoading scenarios through iterator...\n");
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("scenarios/"));
foreach ($iterator as $key => $value)
{
print("| ".$key." => ".$value."\n");
$zip -> addFile(realpath($key), $key) or die ("Error: could not add file: ".$key);
}
print("\nTotal number of files: ".$zip -> numFiles."\nArchive status: ".$zip -> status."</pre>");
$zip -> close();
RE: [?] PHP ZipArchive... by matty on 11-21-2010 at 03:41 PM
Di you need to add the folder structure manually? I have never worked with ZipArchive before...
RE: [?] PHP ZipArchive... by whiz on 11-21-2010 at 04:12 PM
I've tried using $zip->addEmptyDir() for the two directories and their subdirectories, but it doesn't make any difference.
|