Solved

using include() on a compressed file

Posted on 2003-11-25
2
197 Views
Last Modified: 2013-11-18
I've got a file in a htaccess protected directory, that I want to have downloaded by people authenticated through a mysql database.

the problem that when I use include ("somedir/file.tar.gz"); the result is displayed binary rather than a download prompt.

any suggestions?

Alternately I've tried including a html file from the same directory, and have it redirect to the file in question. this ends up giving the expected login pop-up.. (I thought I could embed the authentication into the redirect link.. NOPE! heh)
0
Comment
Question by:kenfcamp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
lozloz earned 125 total points
ID: 9821298
hi,

you want to use header to tell the browser to download the file, then you need to use fopen to open the file and give it to the browser.. here's an example:

<?
$path = "somefile/file.tar.gz";
$thefile = file_get_contents($path);
header( "Content-type: application/x-gzip" );
header( "Content-Disposition: attachment; filename=yourchosenfilename.tar.gz" );
print $thefile;
?>

you can probably add some more information in the headers there if you want, such as

header("Content-Length: " . filesize($path));

best to look at the comments here though:

http://uk2.php.net/header

loz
0
 
LVL 14

Author Comment

by:kenfcamp
ID: 9821514
geez!

I was off by one string .. you nailed it..

Thanks !
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question