Search code examples
phpzip

PHP: how extract a zip file?


Is it possible to extract a zip file stored in server using php file operations. The zip file has to be unzipped, I know the location of the file inside server so how can the file will be used for the process. Note- Users don't upload any data they just gives the different textual information which is stored as a zip file and it cannot be used to store in database.

Edit1-can we give html's input tag a DEFAULT PATH of file which has to be uploaded so user will not have to select a file they will just need to press upload button


Solution

  • $zip = new ZipArchive;
    
    $res = $zip->open('file.zip');
    
    if ($res === TRUE) 
    {
        $zip->extractTo('/extract_path/');
        $zip->close();
    }