How to unzip a folder in PHP? [closed]

0

I have a form where an administrator will fill in user data, but I need this administrator to enter a .zip folder where you will have user photos.

I'm using a button to select the .zip file, but I need to unzip this file and then use what's inside it.

<form action='pageinicial.php' method='GET' enctype='multipart/form-data'>
    <div class='diview'>
    Certifique-se de preencher os campos login, senha, nome e email!
    <table>
        <thead>
        <tr>
         <th >login</th>
          <th >senha</th>
           <th >nome</th>
           <th >departamento</th>
            <th >nivel</th>      
             <th >email</th> 
             </tr>
        </thead>
        <tbody>   
        <tr> 
           <td id='class_td'><input type='text' name='loginusu' value=''></td>
          <td id='class_td'><input type='text' name='senhausu' value=''></td>
           <td id='class_td'><input type='text' name='nomeusu' value=''></td>
           <td id='class_td'><input type='text'  name ='departamentousu' value=''></td>
           <td id='class_td'><input type='text' name='nivelusu' value=''></td>
            <td id='class_td'><input type='email' name='emailusu' value=''></td>
        </tr>        
        </tbody>
    </table>
    </div>
    <input type='submit' value='Adicionar'/>
<input type='file' name='foto' /><br /><br />
    
asked by anonymous 13.03.2018 / 22:14

1 answer

1
<?php
 $arquivo = getcwd().'/arquivo-teste.zip';
 $destino = getcwd().'/';

 $zip = new ZipArchive;
  $zip->open($arquivo);
   if($zip->extractTo($destino) == TRUE)
   {
    echo 'Arquivo descompactado com sucesso.';
   }
   else
   {
    echo 'O Arquivo não pode ser descompactado.';
   }
  $zip->close();
?>

Or direct:

<?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
    $zip->extractTo('/my/destination/dir/');
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}
?>

Official Documentation

Sources:

Compact

#

    
13.03.2018 / 22:21