title: PHP Warning: ZipArchive::extractTo(): Permission denied error
body: <p>I found this code that takes a zip file and extract it. however I am running into some errors. When I try to upload a zip, i get this error <code>Warning: ZipArchive::extractTo(): Permission denied in /Applications/XAMPP/xamppfiles/htdocs/newLosani/testphp.php on line 26</code> I changed the permissions on the file and folder its going to 777 and 644, neither worked :(</p>
  
  <p>I even tried to change the permissions of file I am uploading to 777 and that didnt work.</p>
  
  <p>Here is the code in question:</p>
  
  <pre><code>&lt;?php
  if($_FILES["zip_file"]["name"]) {
          $filename = $_FILES["zip_file"]["name"];
          $source = $_FILES["zip_file"]["tmp_name"];
          $type = $_FILES["zip_file"]["type"];
  
          $name = explode(".", $filename);
          $accepted_types = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed');
          foreach($accepted_types as $mime_type) {
                  if($mime_type == $type) {
                          $okay = true;
                          break;
                  }
          }
  
          $continue = strtolower($name[1]) == 'zip' ? true : false;
          if(!$continue) {
                  $message = "The file you are trying to upload is not a .zip file. Please try again.";
          }
  
          $target_path = $filename;  // change this to the correct site path
          if(move_uploaded_file($source, $target_path)) {
                  $zip = new ZipArchive();
                  $x = $zip-&gt;open($target_path);
                  if ($x === true) {
                          $zip-&gt;extractTo("/zip/"); // change this to the correct site path
                          $zip-&gt;close();
  
                          unlink($target_path);
                  }
                  $message = "Your .zip file was uploaded and unpacked.";
          } else {
                  $message = "There was a problem with the upload. Please try again.";
          }
          echo $message;
  }
  ?&gt;
  </code></pre>