Jump to content

Problems implementing rar->extract


r_gauti

Recommended Posts

I needed to access a .rar file 'test2009520.rar' contains a txt file 'test2009520.txt' on a Ubuntu server running PHP5. Here's the code -

$rar_file = rar_open('test2009520.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 = "test2009520.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: test2009520.txt Packed size: 9334 Unpacked size: 161610 RAR CLOSE

Warning: fopen(/test/new_name.txt) [function.fopen]: failed to open stream: No such file or directory in /home/default/hypeitools.co.uk/user/htdocs/test.php on line 54

Warning: filesize() [function.filesize]: stat failed for /test/new_name.txt in /home/default/hypeitools.co.uk/user/htdocs/test.php on line 55

Warning: fread(): supplied argument is not a valid stream resource in /home/default/hypeitools.co.uk/user/htdocs/test.php on line 55

Warning: fclose(): supplied argument is not a valid stream resource in /home/default/hypeitools.co.uk/user/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

Link to comment
https://forums.phpfreaks.com/topic/170642-problems-implementing-rar-extract/
Share on other sites

Oops copied wrong output yesterday. Here is the correct output


Filename: test2009520.txt Packed size: 9334 Unpacked size: 161610 RAR CLOSE

Warning: fopen(test2009520.txt) [function.fopen]: failed to open stream: No such file or directory in /home/default/hypeitools.co.uk/user/htdocs/test.php on line 31

Warning: filesize() [function.filesize]: stat failed for test2009520.txt in /home/default/hypeitools.co.uk/user/htdocs/test.php on line 32

Warning: fread(): supplied argument is not a valid stream resource in /home/default/hypeitools.co.uk/user/htdocs/test.php on line 32

Warning: fclose(): supplied argument is not a valid stream resource in /home/default/hypeitools.co.uk/user/htdocs/test.php on line 33

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.