Page 1 of 1

not finding files within archive using tar.class

Posted: Tue May 30, 2006 11:24 am
by jameslabocki
All,

I am having a problem when working with tar.class. I found the class here http://www.koders.com/php/fid7E47CBB434 ... 9A0A2.aspx I've attached my code below and the output which I see after. I think that the class is not finding the files contained in the tar archive but I'm not sure why?

Code: Select all

<?PHP

include('/app/dbx/php/tar.class.php');

$tar = new tar();
$tarfile = "/app/dbx/work/test.tar";
 
// Open an uncompressed tar file
if(!$tar->openTar($tarfile,FALSE)) {
 $message = "Failed to open " . $tarfile;
 print $message;
// applog($message);
} else {
 $message = "Opened " . $tarfile; 
 print $message;
// applog($message);
}
 
// List files in the currently opened tar file(s)
echo "<BR><BR><b>Files in " . $tar->filename . "</b><br>\n";
print "<BR>numFiles: " . $tar->numFiles . "<BR><BR>"; //I added this to print out numFiles
if($tar->numFiles > 0) {
 foreach($tar->files as $id => $information) {
  echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$information[directory]/$information[name]<br>\n"; 
 }
} else {
 echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;There are no files described in this tar archive.<br>\n";
}
echo "<br>\n";

?>

Here's what I see afterwards

(notice numFiles is not undefined so we never go into the foreach loop)

TAR Archive Class

Opened /app/dbx/work/test.tar

Files in /app/dbx/work/test.tar

numFiles:

There are no files described in this tar archive.
[/b]

Posted: Tue May 30, 2006 11:28 am
by PrObLeM
I'm assuming you have files in test.tar right?

Posted: Tue May 30, 2006 11:59 am
by jameslabocki
Yes :)

Posted: Tue May 30, 2006 12:44 pm
by jameslabocki
figured it out ... apparently Sun's tar uses different offset of bytes so the class doesn't work with the. I used GNUtar with no problem!

Sun ... :roll: