kristo5747 Posted December 22, 2011 Share Posted December 22, 2011 I wrote a very simple web form that allows my user to view text files from within their Internet browser. 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. I got a prototype working but it only compresses the first file. The second or third files are ignored. Here's my code <HTML><body><form name="myform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset><label for="DBRIDs">RIDs</label><input type="text" id="DBRIDs" name="DBRIDs" > </fieldset></form></body></HTML> <?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 .= '<tr><td><a href="' . basename($mydir) . '/' . $filename . '" target="_blank">' . $filename . '</a></td></tr>'; $ZIPresult .= basename($mydir) . '/' . $filename; } if ($result) { $result = "<table><tbody><tr><td>Search Results.</td></tr> $result</table>"; shell_exec("zip -9 SearchResult.zip ". $ZIPresult ." > /dev/null "); } return $result; } The hyperlinks pointing to the file(s) are generated just fine. The ZIP file however only contains the first file listed in the results. How can I get the ZIP file to capture ALL the files returned?? Thanks for your input. **PS: The new ZipArchive() library/class is not available on our production environment so I chose to use the Unix utility ZIP instead.** Quote Link to comment https://forums.phpfreaks.com/topic/253693-unable-to-zip-more-than-one-file-at-a-time/ Share on other sites More sharing options...
kicken Posted December 22, 2011 Share Posted December 22, 2011 You probably just need to put a space between the filenames. Right now your $ZIPResult variable is going to hold all the filenames squished up together in one long string without any spaces separating them. $ZIPresult .= basename($mydir) . '/' . $filename.' '; Quote Link to comment https://forums.phpfreaks.com/topic/253693-unable-to-zip-more-than-one-file-at-a-time/#findComment-1300549 Share on other sites More sharing options...
kristo5747 Posted December 22, 2011 Author Share Posted December 22, 2011 You probably just need to put a space between the filenames. Right now your $ZIPResult variable is going to hold all the filenames squished up together in one long string without any spaces separating them. $ZIPresult .= basename($mydir) . '/' . $filename.' '; That was it . I can now ZIP multiple files. Thanks a million! Quote Link to comment https://forums.phpfreaks.com/topic/253693-unable-to-zip-more-than-one-file-at-a-time/#findComment-1300560 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.