Professional Web Applications Themes

File download behavior different betwen Netscape/IE - PHP Development

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 ...

  1. #1

    Default 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 [url]www.php.net[/url])

    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

    Alexander Gilman Carver Guest

  2. #2

    Default Re: File download behavior different betwen Netscape/IE

    On Sat, 13 Sep 2003 05:04:06 +0000 (UTC), Alexander Gilman Carver
    <agcmehotmail.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

    Allan Savolainen Guest

  3. #3

    Default Re: File download behavior different betwen Netscape/IE

    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
    [url]http://www.quanetic.com[/url]
    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 [url]www.php.net[/url])
    >
    > 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
    >
    Kurt Milligan Guest

  4. #4

    Default Re: File download behavior different betwen Netscape/IE

    Allan Savolainen <raynetedu.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.
    Alexander Gilman Carver Guest

  5. #5

    Default Re: File download behavior different betwen Netscape/IE

    Kurt Milligan <junkatnospammilliganshome.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. :)
    Alexander Gilman Carver Guest

Similar Threads

  1. Download Repeat Region Server Behavior
    By funkster in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 3
    Last Post: May 4th, 08:11 AM
  2. How do I add download behavior to a button?
    By the squink in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 0
    Last Post: October 19th, 03:15 PM
  3. My game doesnt download in IE or NetScape
    By ottvor in forum Macromedia Director 3D
    Replies: 1
    Last Post: April 17th, 09:40 AM
  4. Download with Netscape
    By Pierre Laporte in forum PHP Development
    Replies: 0
    Last Post: September 21st, 05:52 PM
  5. php download management - netscape/mozilla bug
    By Freddy in forum PHP Development
    Replies: 0
    Last Post: September 11th, 06:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139