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: Open file in ML(SMLNJ) I have a string value which has value
Possible Duplicate: open download dialog with php I have a link in my page
Possible Duplicate: Open file from complete path under cursor in Vim Let's say I
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: Why does BinaryWriter prepend gibberish to the start of a stream? How
Possible Duplicate: Checking for an SQL result in VB.NET I have login form which
Possible Duplicate: Not possible to launch a file on a network using Java Desktop?
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be

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.