473,795 Members | 2,410 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.b ar.tar.gz"');
header('Content-Length: '. filesize($_GET['archive']);
if ( $file = fopen($_GET['archive'], 'rb') )
{
while ( !feof($file) and (connection_sta tus() == 0) )
{
print(fread($fi le, 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 4735
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=\"$arc hive\"");
readfile($archi ve);
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 "applicatio n/x-gzip" rather than
"applicatio n/octet-stream")

$fp = fopen("$filepat h/$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.b ar.tar.gz"');
header('Content-Length: '. filesize($_GET['archive']);
if ( $file = fopen($_GET['archive'], 'rb') )
{
while ( !feof($file) and (connection_sta tus() == 0) )
{
print(fread($fi le, 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.lah ti.fi> summoned the power of the electron to profess:
| header("Content-Type: application/download\n");
| header("Content-Disposition: filename=\"$arc hive\"");
| readfile($archi ve);
| 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**@atnospamm illiganshome.ne t> 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 "applicatio n/x-gzip" rather than
| "applicatio n/octet-stream")

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

| $fp = fopen("$filepat h/$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
4934
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=" &" & StrFileName Now the it works fine in ie5.5 sp2 but no ie5.5 sp1 it prompts the user twice the open dialog box.
4
3808
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 audio file initiates client-side streaming/playing of the audio file. Is there a way with Javascript to make a left-click trigger a download of the file instead? BTW, I don't want to have convert the mp3 file to winzip to make this happen,...
2
2281
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 Netscape. On Netscape rather than give the user the save option it simply displays the file. I also see problems on the mac platform - no save box - it displays the file as in netscape. Is there a universally accepted way of doing this sort of...
19
4024
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 unknown types zip files etc.) ? thanks Mel
15
4780
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 button will verify the information that has been entered and updates the data base if the data is correct. Update will throw an exception if the data is not validate based on some given rules. I also have a custom error handling page to show the...
20
2648
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
6510
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" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
2
2174
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 SubmitButton_Click (object sender, System.EventArgs e) { // Set up the response to write the print file to the client Response.Clear (); Response.Buffer=false;
38
5079
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.
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10437
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10214
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6780
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.