Skip to content
Advertisement

extract 7z extension – PHP

I am wondering if PHP can extract the *.7z extension. I have searched a lot about it and I all what I see is *.zip, *.rar etc… but not 7z. Here is the code that I have tried. ZipArchive(); is not supporting 7z.

$zip = new ZipArchive();
$x = $zip->open($target_path); //I have tried ,ZipArchive::CREATE|ZipArchive::OVERWRITE after path but no luck.

if($x === true) {
  $zip->extractTo('../uploads/ext');
  $zip->close();

  echo "Your zip file has been unpacked.";
}
else
{
  echo 'not unpacked!';
}

I have many 7z files and I am looking to let PHP unpack them to get information from them. I have looked at 7zip website for some resources but no luck. Its looks like ZipArchive(); cannot open *.7z

Does anyone have any idea about this?

I need to unzip 7z extension by PHP.

Advertisement

Answer

to extract 7z extension you will need some kind of library, because ZipArchive() function is only for .zip archives.

To extract .7z you can use for example this library (Wrapper 7-zip (p7zip)): https://github.com/Gemorroj/Archive7z

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement