简体   繁体   中英

how to unzip .zip file in codeigniter 4 (PHP)

I am trying to extract zip file in codeigniter 4... I have the code below

    $file_name =  session()->get('file_name');
        
        // Zip file name
    $filename = "/public/$file_name";

    $zip = new \ZipArchive;
    
    $res = $zip->open($filename);
    
    if ($res === true) {

 // Unzip path
        $path = "/public";

        // Extract file
        $zip->extractTo($path);
        $zip->close();

        return 'Site Updated Successfully';
        
    } else {
        
        return "failed to update $filename!";
        
    }
        }

but I get this result: return "failed to update $filename;";

Please can someone help me fix the issue with the code.

This has nothing specifically to do with Codeigniter. It's just using PHP and ZipArchive. The code looks OK - be sure the file is really in the /public/ directory and that it is a zip archive. The PHP site has examples that are like $zip = new ZipArchive; (without the \ char); maybe try that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM