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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:35:39+00:00 2026-05-16T01:35:39+00:00

i have a tar archive on the server that must be downloadable through php.

  • 0

i have a tar archive on the server that must be downloadable through php. This is the code that i’ve used:

$content=file_get_contents($tar);
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=$tar");
header("Content-Length: ".strlen($content));    
unlink($name);
die($content);

The file is downloaded but it’s broken and it can’t be open. I think that there’s something wrong with headers because the file on the server can be open without problems. Do you know how can i solve this problem?

UPDATE
I’ve tried to print an iframe like this:

<iframe src="<?php echo $tar?>"></iframe>

And the download works, so i’m sure that there’s something missing in headers.

  • 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-16T01:35:40+00:00Added an answer on May 16, 2026 at 1:35 am

    I have used this code when I have had to do it:

    function _Download($f_location, $f_name){
     header('Content-Description: File Transfer');
     header('Content-Type: application/octet-stream');
     header('Content-Length: ' . filesize($f_location));
     header('Content-Disposition: attachment; filename=' . basename($f_name));
     readfile($f_location);
     }
    
    _Download("../directory/to/tar/raj.tar", "raj.tar");
    //or
    _Download("/var/www/vhost/domain.com/httpdocs/directory/to/tar/raj.tar", "raj.tar");
    

    Try that.

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

Sidebar

Related Questions

I have written a shellscript which tries to pull a tar file from an
In my web application, users can download a .tar.gz archive containing the app files.
I have a Rails app that archives high-res images (and thumbs) on S3 (via
I have absolutly no idea how to unpack the created archive. I give you
If I have a clone of a git repository as a cached copy on
Since there are some major privacy issues with alot of social networking sites I
I'm writing a web application in Python, intended for use by teachers and pupils
I was fairly happy with my Mercurial setup until now. I use it for
In Django I'm looking for a way to serve several different files at once.

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.