Wer Dateien unter Linux entpacken will und 7zip zur Verfügung hat kann dieses über PHP erledigen werden. Mit der Funktion un7rar. Die Ausgabe von 7zip wird in den Quellpfad der zu entpackenden Datei als .7zipped abgelegt. Um zu Überprüfen ob das entpacken ohne Probleme verlaufen ist, kann mit der Funktion chkLog der entsprechende String Everything is Ok in der Logdatei gesucht werden.
Ich werden bei Gelegenheit noch eine einzelne Klassen zusammenbasteln.
.7zipped
7-Zip 4.61 beta Copyright (c) 1999-2008 Igor Pavlov 2008-11-23 p7zip Version 4.61 (locale=C,Utf16=off,HugeFiles=on,1 CPU) Processing archive: [...].rar Extracting [...] Everything is Ok Size: [...] Compressed: [...]
Funktionen
$zip7path="/usr/local/lib/p7zip/7z";
function un7rar($arRAR,$download,$output) {
global $zip7path;
if (count($arRAR)>0) {
foreach($arRAR as $RARfile) {
$trar=str_replace($download,"",$RARfile);
$trar=stristr_res($trar,"/");
$piped=stristr_res(str_replace($download,"",$RARfile),"/");
if (!file_exists($download.$piped."/.7zipped")) {;
$cmd="cd ".$download."; ".$zip7path." -y -o".$output.$trar." e ".str_replace($download,"",$RARfile)." > ".$piped."/.7zipped";
$cmds[]=$cmd;
echo std($cmd);
}
}
}
}
function chkLog($str) {
return preg_match("/Everything is Ok/i",$str);
}
function std($cmd) {
$back="";
$io = array();
$p = proc_open($cmd,
array(1 => array('pipe', 'w'),
2 => array('pipe', 'w')),
$io);
/* Read output sent to stdout. */
while (!feof($io[1])) {
$back .= htmlspecialchars(fgets($io[1]),
ENT_COMPAT, 'UTF-8');
}
/* Read output sent to stderr. */
while (!feof($io[2])) {
$back .= htmlspecialchars(fgets($io[2]),
ENT_COMPAT, 'UTF-8');
}
fclose($io[1]);
fclose($io[2]);
proc_close($p);
return $back;
}