473,418 Members | 2,290 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,418 software developers and data experts.

File download behavior different betwen Netscape/IE


I have written a pair of scripts that are supposed to work together to
display an index of files and then, upon the user choosing the files (with
checkboxes on an HTML form submitted to itself), tar/gzip the file and
send it to them.

To this end the first script performs an exec() call and generates the
archive (it's a random number but we'll call it foo.bar.tar.gz) and then
writes a META tag into the page after it submits the HTML form to itself:

<META HTTP-EQUIV="Refresh"
Content="2;URL=http://server.tld/path/to/sendprogram.php?
archive=foo.bar.tar.gz">

(all on one line of course).

The second script takes in the parameter, sets the headers and tries to
send the file:

header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="foo.bar.tar.gz"');
header('Content-Length: '. filesize($_GET['archive']);
if ( $file = fopen($_GET['archive'], 'rb') )
{
while ( !feof($file) and (connection_status() == 0) )
{
print(fread($file, 8192));
flush();
}
}
fclose($file);
unlink($_GET['archive']);

(note the above code was taken from user submissions within the online
manuals at www.php.net)

Now the odd part:

If I'm using IE, this works just fine. I submit the form, wait a few
moments, and then the file transfer dialog box pops up and begins the
download. The file is fine and contains no errors.

If I'm using Netscape 7.1, I still get the file transfer dialog box but
then it never transfers the file. I get a zero byte file. If I remove
the unlink() from the second script, it works (but leaves behind the
archive of course).

Does anyone have any idea why this might be happening and what the right
way or workaround might be?

Thanks

Jul 16 '05 #1
4 4717
On Sat, 13 Sep 2003 05:04:06 +0000 (UTC), Alexander Gilman Carver
<ag***@hotmail.com> wrote:

Dunno why that happens, but I've used this without problems (except in
Mac IE you must have the filename as the last element in URL, if not
it uses the filename of your PHP script)

header("Content-Type: application/download\n");
header("Content-Disposition: filename=\"$archive\"");
readfile($archive);
unlink($archive);

- allan savolainen

Jul 16 '05 #2
Couple of things;

First, I'm not sure why you are going through the "Refresh" step;
why not just send the file right after the exec() call?
Also, the output step could be simplified, so the whole thing might look
like:

$filepath = 'whatever...';
$filename = 'foo.bar.tar.gz';
exec("tar cvzf $filepath/$filename (stuff to be tar'd)");

header('Content-Type: application/octet-stream');
(I'm not sure the other headers are necessary, but maybe...
also, you might try "application/x-gzip" rather than
"application/octet-stream")

$fp = fopen("$filepath/$filename", 'rb');
if($fp)
{
fpassthru($fp);
fclose($fp);
}
Now, I'm not sure this will solve your Netscape problem, but I have seen
similar things happen in the past where the order that things actually
happen aren't always the same as the order they are in the script (and
actually, I had this problem with IE5.5 (PC) and some Mac versions of
IE). What I did to get around it was to write the file to some tmp
directory, then have a cron script run on a regular basis to clean out
files older than X minutes, rather than having the page do the delete.

HTH
-Kurt
http://www.quanetic.com
Alexander Gilman Carver wrote:
I have written a pair of scripts that are supposed to work together to
display an index of files and then, upon the user choosing the files (with
checkboxes on an HTML form submitted to itself), tar/gzip the file and
send it to them.

To this end the first script performs an exec() call and generates the
archive (it's a random number but we'll call it foo.bar.tar.gz) and then
writes a META tag into the page after it submits the HTML form to itself:

<META HTTP-EQUIV="Refresh"
Content="2;URL=http://server.tld/path/to/sendprogram.php?
archive=foo.bar.tar.gz">

(all on one line of course).

The second script takes in the parameter, sets the headers and tries to
send the file:

header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="foo.bar.tar.gz"');
header('Content-Length: '. filesize($_GET['archive']);
if ( $file = fopen($_GET['archive'], 'rb') )
{
while ( !feof($file) and (connection_status() == 0) )
{
print(fread($file, 8192));
flush();
}
}
fclose($file);
unlink($_GET['archive']);

(note the above code was taken from user submissions within the online
manuals at www.php.net)

Now the odd part:

If I'm using IE, this works just fine. I submit the form, wait a few
moments, and then the file transfer dialog box pops up and begins the
download. The file is fine and contains no errors.

If I'm using Netscape 7.1, I still get the file transfer dialog box but
then it never transfers the file. I get a zero byte file. If I remove
the unlink() from the second script, it works (but leaves behind the
archive of course).

Does anyone have any idea why this might be happening and what the right
way or workaround might be?

Thanks


Jul 16 '05 #3
Allan Savolainen <ra****@edu.lahti.fi> summoned the power of the electron to profess:
| header("Content-Type: application/download\n");
| header("Content-Disposition: filename=\"$archive\"");
| readfile($archive);
| unlink($archive);

I'll give this a try (server's power supply died last night :( ).
Fortunately, the archive name is the last thing on the refreshed URL.
Jul 16 '05 #4
Kurt Milligan <ju**@atnospammilliganshome.net> summoned the power of the electron to profess:
| Couple of things;

| First, I'm not sure why you are going through the "Refresh" step;
| why not just send the file right after the exec() call?
| Also, the output step could be simplified, so the whole thing might look
| like:

Well, I'm doing the refresh step because I want the form back. This is a
replacement for an existing download page. The existing page only
provides links to each file which you perform a right-click/save as (or
similar). The idea of the archiving is to make downloading multiple files
easier.
| $filepath = 'whatever...';
| $filename = 'foo.bar.tar.gz';
| exec("tar cvzf $filepath/$filename (stuff to be tar'd)");

| header('Content-Type: application/octet-stream');
| (I'm not sure the other headers are necessary, but maybe...
| also, you might try "application/x-gzip" rather than
| "application/octet-stream")

I know the Content-Length header isn't necessary but very useful to give a
progress meter for the download.

| $fp = fopen("$filepath/$filename", 'rb');
| if($fp)
| {
| fpassthru($fp);
| fclose($fp);
| }
| Now, I'm not sure this will solve your Netscape problem, but I have seen
| similar things happen in the past where the order that things actually
| happen aren't always the same as the order they are in the script (and
| actually, I had this problem with IE5.5 (PC) and some Mac versions of
| IE). What I did to get around it was to write the file to some tmp
| directory, then have a cron script run on a regular basis to clean out
| files older than X minutes, rather than having the page do the delete.
I had thought of the cron job as well but the files are going to be too
big to leave on the server for a while. Some of them are going to reach
upwards of 1 GB or more depending on how many files are selected for
download. The archive doesn't compress much because the files being
downloaded are very nearly compressed (mostly images). I gain a couple
percent compression by compressing one large tar simply because it gives
gzip more data to work with.

I'll give your script a try as well. If I can support IE and Netscape,
that's all I'm going to worry about. :)
Jul 16 '05 #5

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

Similar topics

1
by: Navin | last post by:
hi, guys i am using the following code to force a file download dialog in asp Response.ContentType = "application/vnd.ms-excel" response.AddHeader "content-disposition","attachment; filename="...
4
by: Robert Oschler | last post by:
Hello, I have a web site that has an audio file on it that I make available for download. Right now I'm using the "right-click/save-as" approach. This is because left-clicking the link to the...
2
by: jim | last post by:
I'm trying to find the best way to allow web visitors to download text files (.txt, .wri & .zap file extensions). I'm having some luck. I say some because the open/save box opens with IE but not...
19
by: Mel | last post by:
when downloading files from my site, when file types are known (i.e *.doc) browsers open the file for viewing. is there a way to disable that and just present the save as dialog (same as for...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
20
by: plmanikandan | last post by:
Hi, I need to read a file line by line.each line contains different number of characters.I opened file using fopen function.is there any function to read the file line by line Regards, Mani
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
2
by: msxkim | last post by:
My web app writes some binary data to a file at the client site via Response.BinaryWrite. This action is accomplished in response to a button click, with C# code behind as follows: private void...
38
by: ted | last post by:
I have an old link that was widely distributed. I would now like to put a link on that old page that will go to a new page without displaying anything.
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.