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 7984727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:21:54+00:00 2026-06-04T11:21:54+00:00

I am trying to add files into a zip by sending the file names

  • 0

I am trying to add files into a zip by sending the file names from a HTML form.
The HTML code is

<form action="act.php" method="POST">
<input type="checkbox" name="send1" value="filename1.extension">
<input type="checkbox" name="send1" value="filename2.extension">
</form>

The PHP

I tried in two ways
Method 1:

$zipfilename="abcd.zip";
$zip= new ZipArchive();
$zip->open($zipfilename, ZipArchive::CREATE);
foreach($_POST['send1'] as $filename)
{
$zip->addFile($filename);
}
$zip->close();

Method 2:

$zipfilename="abcd.zip";
$filestozip=array();
foreach($_POST['send1'] as $filename)
{
$filestozip[]=$filename;
}

$zip= new ZipArchive();
$zip->open($zipfilename, ZipArchive::CREATE);

foreach($filestozip as $filename2)
{
$zip->addFile($filename2);}
}

$zip->close();

But the Zip File is not getting created. I tried to check the Zip syntax with static code for $filetozip as

$filestozip[0]="filename1.extension";
$filestozip[0]="filename1.extension";

It worked. But when the data is from another HTML page dynamically it does not work. What is the error in my code?

  • 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-06-04T11:21:56+00:00Added an answer on June 4, 2026 at 11:21 am

    Found the problem. There is no problem in my logic.

    $zip->addFile($filename);
    

    As I said previous the data for the $filename variable is received from a HTML for in which any spaces are replaced by %20 intentionally by me. The reason for such replacement is to enable links to the file using the data. But if the space is replaced by %20 zipArchive::addFile() does not add the zip file which ultimately result in Zip creation fail.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to update (add/modify files) an existing JAR file, and this code (using
I'm trying to add .css and .js file in my HTML template files that
I am trying to add some files to a ZIP file, it creates the
Im trying to add some short file names to a Wise installer to fix
I'm trying to add a css file in my zend application layout.php the problem
I am trying to add two localization resource files into my MVC3 App_GlobalResources. I
I am trying to download a 2 files by creating the zip file on
I'm trying to add two image files into the solution, so they will be
I'm trying to add different icon overlays over the icons of various files (note:
We are trying to add a custom header (X-Robots-Tag) for sitemap files in IIS

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.