Solved

using include() on a compressed file

Posted on 2003-11-25
2
192 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 125 total points
Comment Utility
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 13

Author Comment

by:kenfcamp
Comment Utility
geez!

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

Thanks !
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now