How to read the rar content in php?

To read the rar content in php, you should have your rar extension enabled first. The extension is located in /php/ext directory. To enable it add this line to php.ini file.
extension = php_rar.dll

If you don’t have a .dll file then it could be downloaded from here php_rar.dll

function read_rar_file($rarfile) {
$rar_file = rar_open($rarfile) or die("Can't open Rar archive");
$entries = rar_list($rar_file); // each entry of a rar

foreach ($entries as $entry) {
	$stream = $entry->getStream(); 
	
	$file = '';
	while (!feof($stream)) {
		$buff = fread($stream, 8192);
		if ($buff !== false) {
			$file .= $buff; // file content for a rar file
		}else {
			break;
		}
	}
        $each_file_content[$entry->getName()] = $file;	
}
fclose($stream);
rar_close($rar_file);
}

Leave a Reply

Your email address will not be published. Required fields are marked *

* Copy This Password *

* Type Or Paste Password Here *

www.000webhost.com