Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

using include() on a compressed file

Posted on 2003-11-25
2
Medium Priority
?
200 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 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

722 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