473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

downloading gz compressed files?

i have a short php script that creates a gz compressed file, but...
when i try to download it, internet explorer doesn't prompt me for a
download location, and then save it at that download location...
instead, it just opens it as it would any old text document... this
is not what i want it to do... i want to be able to download it, not
view it. any ideas on how to do this?

here's the code:

<?
system("ls -l | gzip > test.gz");
print "download <a href=test.gz>here</a>";
?>
Jul 17 '05 #1
3 4855
Après mure réflexion, "yawnmoth" a écrit :
i have a short php script that creates a gz compressed file,
but... when i try to download it, internet explorer doesn't
prompt me for a download location, and then save it at that
download location... instead, it just opens it as it would any
old text document... this is not what i want it to do... i want
to be able to download it, not view it. any ideas on how to do
this?

here's the code:

<?
system("ls -l | gzip > test.gz");
print "download <a href=test.gz>here</a>";
?>


Well you can always right click on the link and 'save
as...'...
--
SeeSchloß - http://www.seeschloss.net

Jul 17 '05 #2
> > <?
system("ls -l | gzip > test.gz");
print "download <a href=test.gz>here</a>";
?>


Your Webserver seems to not send the correct mime-type of the downloaded
file.

Try sending the mime-type on your own using the header() and send the
filedata manually instead of providing a download link.

$fp = fopen("test.gz","rb");
$size = filesize("test.gz");
$content = fread($fp,$size);
fclose($fp);

Header('Content-Type: application/x-zip');
Header('Content-Length: '. $size);
Header('Content-disposition: inline; filename=test.gz');
print $content;
}

(not sure with the mime-type .. you better look it up!)

timo

Jul 17 '05 #3
On Tue, 30 Sep 2003 19:01:15 +0200, "Timo Henke" <we*******@fli7e.de>
wrote:
> <?
> system("ls -l | gzip > test.gz");
> print "download <a href=test.gz>here</a>";
> ?>


Your Webserver seems to not send the correct mime-type of the downloaded
file.

Try sending the mime-type on your own using the header() and send the
filedata manually instead of providing a download link.

$fp = fopen("test.gz","rb");
$size = filesize("test.gz");
$content = fread($fp,$size);
fclose($fp);

Header('Content-Type: application/x-zip');
Header('Content-Length: '. $size);
Header('Content-disposition: inline; filename=test.gz');
print $content;
}

(not sure with the mime-type .. you better look it up!)

timo


that header command looks pretty nifty - thanks! :D

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Dennis Hotson | last post by:
Hi, I'm trying to write a function that adds a file-like-object to a compressed tarfile... eg ".tar.gz" or ".tar.bz2" I've had a look at the tarfile module but the append mode doesn't support...
1
by: Ron Clarke | last post by:
Does anyone know how to get the compressed size of a file on disk? FileInfo.Length gives the uncompressed size of a file, but I need to find the amount of disk space taken up by files in compressed...
8
by: robert | last post by:
Hello, I want to put (incrementally) changed/new files from a big file tree "directly,compressed and password-only-encrypted" to a remote backup server incrementally via FTP,SFTP or DAV.... At...
1
by: KJ | last post by:
I am using the System.Compression.GZipStream class, and I noticed that in certain cases, the resultant compressed file is actually larger than the original. This is almost a constant when...
5
by: rony_16 | last post by:
Hi, I have a problem downloading a file . after i connect to the website and get the stream , i treing to write the file on the HD. public void SaveStreamToFile(string filePath, Stream stream) {...
3
by: Chuck Renner | last post by:
Please help! This MIGHT even be a bug in PHP! I'll provide version numbers and site specific information (browser, OS, and kernel versions) if others cannot reproduce this problem. I'm...
11
by: MadMonk | last post by:
Hi, I need to write a small Windows application (console or forms) (for Windows XP SP2 & Windows Server 2003), which will check a folder for the presence of some files, and if they exist, it...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.