I needed to access a .rar file 'test.rar' contains a txt file 'test.txt' on a Ubuntu server running PHP5. Here's the code -
$rar_file = rar_open('test.rar') or die("Failed to open Rar archive");
$entries = rar_list($rar_file);
foreach ($entries as $entry) {
echo 'Filename: ' . $entry->getName() . "\n";
echo 'Packed size: ' . $entry->getPackedSize() . "\n";
echo 'Unpacked size: ' . $entry->getUnpackedSize() . "\n";
$entry->extract('');
}
// close archive
rar_close($rar_file);
echo "RAR CLOSE<br />";
//HANDLE FILE
$myFile = "test.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo $theData;
There are no error messages with the rar functions but then I can find the files being extracted.
Below is the optput I get on a browser.
Filename: test.txt Packed size: 9334 Unpacked size: 161610 RAR CLOSE
Warning: fopen(test.txt) [function.fopen]: failed to open stream: No such file or directory in /home/....../htdocs/test.php on line 54
Warning: filesize() [function.filesize]: stat failed for test.txt in /home/....../htdocs/test.php on line 55
Warning: fread(): supplied argument is not a valid stream resource in /home/....../htdocs/test.php on line 55
Warning: fclose(): supplied argument is not a valid stream resource in /home/....../htdocs/test.php on line 56
I have tried to run a search for the extracted file but I can't find them on the server????
help!!!!