Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

using include() on a compressed file

Posted on 2003-11-25
2
Medium Priority
?
205 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
2 Comments
 
LVL 13

Accepted Solution

by:
lozloz earned 500 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

876 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