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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:44:23+00:00 2026-05-17T19:44:23+00:00

Possible Duplicate: Open file, write to file, save file as a zip and stream

  • 0

Possible Duplicate:
Open file, write to file, save file as a zip and stream to user for download

I have a txt file in uploads folder where i need to add this file and create a ZIP on fly and prompt the user to download the Zip file which should contain the text file .How do i do this and moreover what are the headers needed for prompting the user for download .can any one Help me out. I have used the same constucts from PHP Manual.Iam Using the same function to zip the file “http://davidwalsh.name/create-zip-php” and iam writing this code and iam getting prompted for zip download but iam getting the caution message when i extarct the file

$zip_file = "my-archive.zip";
$file_path="../../../downloads/";
$files_to_zip = array($file_path."test_testing.txt");
$result = create_zip($files_to_zip,'my-archive.zip');

header('Content-Description: File Transfer');    
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=".$zip_file);
header("Pragma: no-cache");
header("Expires: 0");

readfile($zip_file);    

The Caution error message is “one or more files in this archive uses “..”(parent folder) as part of its folder information “

  • 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-17T19:44:24+00:00Added an answer on May 17, 2026 at 7:44 pm

    In the create_zip() function,
    change

    foreach($valid_files as $file) {
        $zip->addFile($file,$file);
    }
    

    to

    foreach($valid_files as $file) {
        $zip->addFile($file,pathinfo($file,PATHINFO_BASENAME));
    }
    

    This will work as long as you don’t have files with duplicate names but different directories in your array of files

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

Sidebar

Related Questions

Possible Duplicate: Pythonic way to check if a file exists? How can Check if
Possible Duplicate: JavaScript open in a new window, not tab How can I open
Possible Duplicate: Auto-open NERDTree in “EVERY” tab Is there a way to automatically execute
Possible Duplicate: C fopen vs open What is the difference between open() and fopen()
Possible Duplicate: PHP - How to split a paragraph into sentences. I have a
Possible Duplicate: extracting the letter in between tags okie let me give an example
Possible Duplicate: Filetype association with application (C#) I'm writing a C# Windows app to
Possible Duplicate: Using Emacs to recursively find and replace in text files not already
Possible Duplicate: Enable GPS programatically like Tasker Anybody know how to enable the GPS
Possible Duplicate: Div Z-Index issue with Flash movie Okay, is there a way to

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.