Creating zip files with PCLZIP.LIB: invalid variable type error
<p>Trying to make an auto directory lister with a download function for every subdirectory. I'd like to make these subdirectories available as .zip files to allow for easier downloading and to use less bandwith on the server.</p>

<p>The following script was working fine until I added the pclzip.lib and tried to let it create a zip file.</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;?php require_once("pclzip.lib.php");?&gt;
&lt;?php require_once("filesize_lib.php"); ?&gt;

&lt;style type="text/css"&gt;

.readme{
width:500px;
height:150px;
background: silver;
overflow-x: hidden;
overflow-y: scroll;
}


&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;?php
    $readme = "/readme.txt";
    $download = "downloads";
  // Openen
    $dir = new DirectoryIterator('.');
  // Doorlopen
?&gt;
&lt;table width="960px" border="1px"&gt;&lt;tr&gt;&lt;td width="185px"&gt;&lt;strong&gt;Name&lt;/strong&gt;&lt;/td&gt;&lt;td width="50px"&gt;&lt;strong&gt;Type&lt;/strong&gt;&lt;/td&gt;&lt;td width="50px"&gt;&lt;strong&gt;Size&lt;/strong&gt;&lt;/td&gt;&lt;td width="125px"&gt;&lt;strong&gt;Last Modified&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Short description&lt;/strong&gt;&lt;/td&gt;&lt;td width="50px"&gt;&lt;strong&gt;Download&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;?php
    foreach ($dir as $file)
      {
        if (! $file-&gt;isDot()
               &amp;&amp; $file != ".."
            &amp;&amp; $file != "index.php"
            &amp;&amp; $file != "filesize_lib.php"
            &amp;&amp; $file != "downloads"
            )
        {        ?&gt;&lt;tr&gt;&lt;td&gt;&lt;?php
                  echo '&lt;a href="'.$file.'"&gt;'.$file.'&lt;/a&gt;';
                ?&gt;&lt;/td&gt;&lt;td&gt;&lt;?php
                echo filetype($file);
                  ?&gt;&lt;/td&gt;&lt;td&gt;&lt;?php
                  echo fileORdirSize($file).'&lt;br/&gt;';
                 ?&gt;&lt;/td&gt;&lt;td&gt;&lt;?php
                  echo date("M j, Y", filemtime($file));    
                  ?&gt;&lt;/td&gt;&lt;?php
                      if (filetype($file) == "dir"){
                          ?&gt;                  
                          &lt;td&gt;&lt;div class="readme"&gt;&lt;?php
                          echo file_get_contents($file.$readme);    
                          ?&gt;&lt;/div&gt;&lt;/td&gt;&lt;?php
                      } else {
                          ?&gt;&lt;td&gt;Files don't have descriptions, but can be tested directly from this page.&lt;/td&gt;&lt;?php
                      }
                  ?&gt;&lt;td&gt;&lt;?php
                    $zip = new PclZip("tmp/archief.zip");
                        if($zip-&gt;create($file) == 0)
                          die("Error : " . $zip-&gt;errorInfo(true));                
                  echo '&lt;a href="'.$zip.'"&gt;'.$zip.'&lt;/a&gt;';
                  ?&gt;&lt;/td&gt;&lt;/tr&gt;&lt;?php
        }
  }
?&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt; 
</code></pre>

<p>The error I'm receiving is the following:</p>

<pre><code>Invalid variable type p_filelist [code -3]
</code></pre>

<p>Which I believe is due to the fact that I'm feeding pclzip.lib a single variable and not an array. Unfortunately, I don't know how to solve this problem. See the piece of code that is responsible for the problem (according to me) below:</p>

<pre><code>&lt;?php    // ----- Init
    $v_string_list = array();
    $v_att_list = array();
    $v_filedescr_list = array();
    $p_result_list = array();

    // ----- Look if the $p_filelist is really an array
    if (is_array($p_filelist)) {

      // ----- Look if the first element is also an array
      //       This will mean that this is a file description entry
      if (isset($p_filelist[0]) &amp;&amp; is_array($p_filelist[0])) {
        $v_att_list = $p_filelist;
      }

      // ----- The list is a list of string names
      else {
        $v_string_list = $p_filelist;
      }
    }

    // ----- Look if the $p_filelist is a string
    else if (is_string($p_filelist)) {
      // ----- Create a list from the string
      $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
    }

    // ----- Invalid variable type for $p_filelist
    else {
      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
      return 0;
    }?&gt;
</code></pre>
