Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6960753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:26:31+00:00 2026-05-27T15:26:31+00:00

I wrote a very simple web form that allows my user to view text

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:26:31+00:00Added an answer on May 27, 2026 at 3:26 pm

    There are a number of issues here (security, for one, as it appears that you’re not sanitizing your DB inputs), but I’m guess the issue is around the $ZIPresult variable. It doesn’t appear (unless I’m missing something) that you have any spaces between your file names, so the shell_exec call is trying to zip “file1.extfile2.extfile3.ext”. See what happens if you modify this line:

    $ZIPresult .= basename($mydir) . '/' . $filename.' ';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a very simple web form that allows my user to view text
I am creating a very simple web part that accepts entry on a form
I wrote a simple web app to let user input data as they walk
I am writing an app that’s a very simple web service client. I have
I have a very simple web application that have to read and write in
I'm absolute beginner in web technologies. I know that my question is very simple,
I wrote a simple webform that will take the user's information (via POST) and
Thanks to the users community on this forum, I wrote a very simple web
This is a very simple bash script I wrote: #!/bin/bash ITEM_LIST=items.txt LOG_FILE=log.log TOTAL_ITEMS=$(wc -l
I am experiencing some very odd timing behavior from a function I wrote. If

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.