} else { echo " There are no directories described in this tar archive.<br>\n"; } echo "<br>\n"; // List files in the currently opened tar file(s) echo "<b>Files in " . $tar->filename . "</b><br>\n"; if ($tar->numFiles > 0) { foreach ($tar->files as $id => $information) { echo " {$information['directory']}/{$information['name']}<br>\n"; } } else { echo " There are no files described in this tar archive.<br>\n"; } echo "<br>\n"; // Check if a file exists in the tar file if ($tar->containsFile("fake.php")) { echo "<b>This TAR Archive does contain a file called fake.php!</b><br>\n"; } else { echo "<b>This TAR Archive does not contain any files called fake.php!</b><br>\n"; } echo "<br>\n"; // Add a file to the archive if ($tar->addFile("example.php")) { echo "Added 'example.php' to archive!<br>\n"; } else { echo "Could not add 'example.php' to archive!<br>\n"; } echo "<br>\n"; // Save changes to a NEW tar file if (!$tar->toTar("test.tgz", TRUE)) { echo "Could not save Gzipped TAR Archive!<br>\n";
$tar->openTAR("my.tar", FALSE); $tar->appendTar("another.tar", FALSE); $tar->toTar("combined.tgz", TRUE); unset($tar); // Removing 2 files from the new.tar file created above $tar = new tar(); $tar->openTar("new.tar", FALSE); $tar->removeFile("example.php"); $tar->removeFile("example2.php"); $tar->saveTar(); // Saves to currently open TAR file (In this case, new.tar) unset($tar); // Check if a TAR file contains a specific file $tar = new tar(); $tar->openTar("new.tar", FALSE); if ($tar->containsFile("tar.class.php")) { echo "This tar file contains a file named 'tar.class.php'!<br>\n"; } else { echo "This tar file does NOT contain a file named 'tar.class.php'!<br>\n"; } // There is no need to save our tar file since we did not edit it, so delete our tar class unset($tar); // Get information about a file in a TAR file $tar = new tar(); $tar->openTar("new.tar"); // If second argument is not present, default is FALSE $information = $tar->getFile("tar.class.php"); echo "<br>\n<b>Information about tar.class.php!</b><br>\n"; foreach ($information as $key => $value) { echo " {$key} = " . text2html($value) . "<br>\n"; }