1

I have zip which contains like this

Search and find almost similar but not fully qualified for me Link 1 & Link 2

activity_plugin

  • src
    • Controller
      • SomeController.php
      • SomeOtherController.php

I want to extract this two files not the whole directory to my destination directory app/Http/Controller in Laravel framework.

I am able to unzip the whole with root directory src > controller > files but I only want to unzip files to destination.How I can achieve that?

So far tried code -

$destinationPath = 'resources/plugins/';
$file_path = $destinationPath.$fileName;
$zip = new \ZipArchive();
$zip->open($file_path);
$zip_bool = zip_open($file_path);
if ($zip_bool) {
    while ($zip_entry = zip_read($zip_bool)) {
         if (substr(strrchr(zip_entry_name($zip_entry), '/'), 1)) {
            $plugin = substr(strrchr(zip_entry_name($zip_entry), '/'), 1);

            if (basename(dirname(zip_entry_name($zip_entry))) == "Controllers") {
                $dir = app_path()."/Http/Controllers";
                $path = zip_entry_name($zip_entry);
                $zip->extractTo($dir, $x);
            }

            $dir = explode('/', zip_entry_name($zip_entry));
            array_pop($dir);
            $newpath = implode('/', $dir);
        }
    }                                  
}
Community
  • 1
  • 1

0 Answers0