Unable to zip more than one file at a time
<p>I wrote a very simple web form that allows my user to view text files from within their Internet browser.</p>

<p>Occasionally, the search criteria entered returns more than one file. So I want to implement a feature whereby the text files returned by the search are compressed into a ZIP.</p>

<p>I got a prototype working but it only compresses the first file. The second or third files are ignored.</p>

<p>Here's my code</p>

<pre><code>&lt;HTML&gt;&lt;body&gt;&lt;form name="myform" method="post" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;"&gt;
&lt;fieldset&gt;&lt;label for="DBRIDs"&gt;RIDs&lt;/label&gt;&lt;input type="text" id="DBRIDs" name="DBRIDs" &gt;
&lt;/fieldset&gt;&lt;/form&gt;&lt;/body&gt;&lt;/HTML&gt;
&lt;?php
function check_search() {
 if (isset($_POST['submit'])) {if (!empty($_POST['DBRIDs'])) { $results = getFiles(); }
        }       else $errors = "Please enter something before you hit SUBMIT.";
 return Array($results, $errors);
}
function getFiles() {
 $result = null;
 $ZIPresult = null;
 if (empty($_POST['DBRIDs'])) { return null; }
 $mydir = MYDIR; 
 $dir = opendir($mydir);
 $DBRIDs = $_POST['DBRIDs'];
 $getfilename = mysql_query("select filename from search_table where rid in (" . $DBRIDs . ")") or die(mysql_error());
 while ($row = mysql_fetch_array($getfilename)) {
 $filename = $row['filename'];
 $result .= '&lt;tr&gt;&lt;td&gt;&lt;a href="' . basename($mydir) . '/' . $filename . '" target="_blank"&gt;' . $filename . '&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;';
 $ZIPresult .= basename($mydir) . '/' . $filename;
} 
if ($result) {
$result = "&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Search Results.&lt;/td&gt;&lt;/tr&gt; $result&lt;/table&gt;";
shell_exec("zip -9 SearchResult.zip ". $ZIPresult ." &gt; /dev/null ");
} return $result;
}
</code></pre>

<p>The hyperlinks pointing to the file(s) are generated just fine. The ZIP file however only contains the first file listed in the results. </p>

<p>How can I get the ZIP file to capture ALL the files returned??</p>

<p>Thanks for your input.</p>

<p><strong>PS: The new ZipArchive() library/class is not available on our production environment so I chose to use the Unix utility ZIP instead.</strong></p>
