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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:49:23+00:00 2026-05-27T13:49:23+00:00

It seems I successfully create an on-the-fly zip archive (filesize and file_exists both return

  • 0

It seems I successfully create an on-the-fly zip archive (filesize and file_exists both return the expected values) but when I attempt to actually download it, I receive an empty ZIP file.
Curiously enough this error occurs with both readfile and fread. This is my code

$filename = $zip;
    $handle = fopen($filename, 'r');
    if ($handle === false)
    {
        die('Could not read file "' . $filename . '"');
    }

    header('Content-type: application/zip');
    header('Content-Disposition: attachment; filename="fsdownload.zip"');
    header('Cache-Control: private');
    while (!feof($handle))
    {
        echo fread($handle, 8192);
    }
    fclose($handle);

This works fine for zip-Files < 10 MB. Any thoughts on what the problem might be?

  • 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-27T13:49:23+00:00Added an answer on May 27, 2026 at 1:49 pm

    To avoid consuming too much memory, you can use ZipStream or PHPZip, which will send zipped files on the fly to the browser, divided in chunks, instead of loading the entire content in PHP and then sending the zip file.

    Both libraries are nice and useful pieces of code. A few details:

    • ZipStream “works” only with memory, but cannot be easily ported to PHP 4 if necessary (uses hash_file())
    • PHPZip writes temporary files on disk (consumes as much disk space as the biggest file to add in the zip), but can be easily adapted for PHP 4 if necessary.

    Related SO questions:

    • Generating ZIP files with PHP + Apache on-the-fly in high speed?
    • Create a zip file using PHP class ZipArchive without writing the file to disk?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seems like a simple enough question but I can't seem to find the answer.
Seems like as really simple thing to do, but I just can't track it
What would the proper way be to modify values on the fly as they
I'm working with django-piston to attempt to create an API that supports oAuth. I
This seems like a fairly simple problem to me but I have been having
I'm trying to create a Zip file from .Net that can be read from
How can I create 7-Zip archives from my C# console application? I need to
Seems to me most of developers completely ignore this features. People prefer handling security
Seems like a simple problem: I have an SVN repo inside our firewall. I
Seems so basic, I can't believe I don't know this! I just need a

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.