Home arrow PHP arrow Page 5 - TAR File Management With PHP Archive_Tar

Building An Index - PHP

Need to create or manipulate a TAR file through your Web browser? Take a look at the PEAR Archive_Tar class, which exposes a simple, yet extremely powerful, API to perform manipulation of TAR and TGZ archives through a PHP script. Possible applications include a TAR file viewer and a Web-based backup utility.

TABLE OF CONTENTS:
  1. TAR File Management With PHP Archive_Tar
  2. Back To Basics
  3. Zip Zap Zoom
  4. Adding It All Up
  5. Building An Index
  6. In And Out
  7. X-Ray Vision
  8. ... And Packing Up
By: The Disenchanted Developer, (c) Melonfire
Rating: starstarstarstarstar / 41
July 17, 2003

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

You can obtain a list of all the files in a TAR archive with the Archive_Tar object's listContents() method, which returns an array of arrays containing detailed information on the contents of the archive. Each element of the returned array represents a file in the source archive, each element is itself structured as an associative array of key-value pairs containing details on the file name and path (key "filename"), size ("size"), owner and group ID ("uid" and "gid"), permissions ("fileperms"), last modification time ("mtime") and whether the entry is a file or directory ("type").

Consider the following example, which demonstrates by using the
listContents() method to obtain a list of all the files within a TAR file, together with their size and last modification times:


<?php

// include class
require("Tar.php");

// create tar file
$tar = new Archive_Tar("data.tar");

// read and print tar file contents
if (($arr = $tar->listContent()) != 0)
{
foreach ($arr as $a)
{
echo $a['filename'] . ", " . $a['size'] . " bytes, last modified on " . date("Y-m-d", $a['mtime']) . "\r\n";
}
}

?>

Here's an example of the output:


scripts/pear.bat, 1570 bytes, last modified on 2002-04-09 scripts/pear.in, 6145 bytes, last modified on 2002-04-09 scripts/pearize.in, 4549 bytes, last modified on 2002-01-31 scripts/pearwin.php, 7507 bytes, last modified on 2002-02-20 scripts/php-config.in, 511 bytes, last modified on 2001-08-13 scripts/phpextdist, 620 bytes, last modified on 2001-01-10 scripts/phpize.in, 727 bytes, last modified on 2002-04-17 scripts/phptar.in, 5322 bytes, last modified on 2001-09-28 scripts/test2.php, 487 bytes, last modified on 2002-09-28



 
 
>>> More PHP Articles          >>> More By The Disenchanted Developer, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: