not finding files within archive using tar.class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jameslabocki
Forum Newbie
Posts: 6
Joined: Tue May 30, 2006 11:08 am
Location: Tampa, FL

not finding files within archive using tar.class

Post 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]
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

I'm assuming you have files in test.tar right?
jameslabocki
Forum Newbie
Posts: 6
Joined: Tue May 30, 2006 11:08 am
Location: Tampa, FL

Post by jameslabocki »

Yes :)
jameslabocki
Forum Newbie
Posts: 6
Joined: Tue May 30, 2006 11:08 am
Location: Tampa, FL

Post 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:
Post Reply