fopen, fpassthru downloading

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve

    fopen, fpassthru downloading

    hello all

    im looking to make a download script as i cannot use the .htaccess to
    control directory access to files as im using a php login system using
    mysql and sessions.

    i have been playing about with fopen and fpassthru but having a few
    problems making the file download. The files involved would mainly be
    but not limited to .pdfs, .docs and .zips

    i have created the following:

    $filepath = '/home/me/folder/file.zip';
    $size = filesize($filep ath);

    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=downlo ad.zip");
    header("Content-Length: ".$size);

    $ok = fopen($filepath , 'rb');
    fpassthru($ok);


    this pops up the download box and downloads in firefox, but in ie it
    pops up the box and then fails. any ideas?

    im guessing its something else that i need to put into my headers but
    i've no idea what. i've been playing with cache and the mime type but
    this seems to download still in firefox but display the text version of
    the zip file in the window in ie.

    Thanks for any advice.
  • Terence

    #2
    Re: fopen, fpassthru downloading

    Steve wrote:
    [color=blue]
    > hello all
    >
    > im looking to make a download script as i cannot use the .htaccess to
    > control directory access to files as im using a php login system using
    > mysql and sessions.
    >
    > i have been playing about with fopen and fpassthru but having a few
    > problems making the file download. The files involved would mainly be
    > but not limited to .pdfs, .docs and .zips
    >
    > i have created the following:
    >
    > $filepath = '/home/me/folder/file.zip';
    > $size = filesize($filep ath);
    >
    > header("Content-Type: application/octet-stream");
    > header("Content-Disposition: attachment; filename=downlo ad.zip");
    > header("Content-Length: ".$size);
    >
    > $ok = fopen($filepath , 'rb');
    > fpassthru($ok);
    >
    >
    > this pops up the download box and downloads in firefox, but in ie it
    > pops up the box and then fails. any ideas?
    >
    > im guessing its something else that i need to put into my headers but
    > i've no idea what. i've been playing with cache and the mime type but
    > this seems to download still in firefox but display the text version of
    > the zip file in the window in ie.
    >
    > Thanks for any advice.[/color]

    I've done with before with almost exactly the same set of headers and
    mine works just fine. The only difference being that I use

    Content-Type: application/force-download;
    instead of your
    Content-Type: application/octet-stream;

    I know all modern user-agents (including IE) support this type but I
    haven't tested it on old browsers.



    Comment

    • Steve

      #3
      Re: fopen, fpassthru downloading

      Terence wrote:[color=blue]
      >
      > I've done with before with almost exactly the same set of headers and
      > mine works just fine. The only difference being that I use
      >
      > Content-Type: application/force-download;
      > instead of your
      > Content-Type: application/octet-stream;
      >
      > I know all modern user-agents (including IE) support this type but I
      > haven't tested it on old browsers.
      >[/color]
      thanks for your reply, still no luck though

      it seems as though every header i try seems to work in firefox but
      nothing works in ie, even a combination of headers.

      at the moment with:

      header("Content-Type: application/force-download");
      header("Content-Disposition: attachment; filename=\"down load.zip\"");
      header("Content-Length: ".$size);

      it trys to download the actual php file instead, and then fails if i
      proceed. this is really confusing because reading around, others have
      experienced success with similar headers.

      Comment

      • Phil Roberts

        #4
        Re: fopen, fpassthru downloading

        With total disregard for any kind of safety measures Steve
        <kibblerok@hotm ail.com> leapt forth and uttered:
        [color=blue]
        > it seems as though every header i try seems to work in firefox
        > but nothing works in ie, even a combination of headers.[/color]

        IE is known for it's quirky and often deliberatly contrary handling
        of MIME types. Most of the times it seems to guess the MIME type from
        the originating file header rather than listening to the info that
        the server gives it...

        --
        Phil Roberts | Dork Pretending To Be Hard | http://www.flatnet.net/

        Comment

        • Steve

          #5
          Re: fopen, fpassthru downloading

          Phil Roberts wrote:[color=blue]
          > With total disregard for any kind of safety measures Steve
          > <kibblerok@hotm ail.com> leapt forth and uttered:
          >
          >[color=green]
          >>it seems as though every header i try seems to work in firefox
          >>but nothing works in ie, even a combination of headers.[/color]
          >
          >
          > IE is known for it's quirky and often deliberatly contrary handling
          > of MIME types. Most of the times it seems to guess the MIME type from
          > the originating file header rather than listening to the info that
          > the server gives it...
          >[/color]
          it sure does

          i've found a solution albeit unsatisfactory. the script has to be called
          via a link into a new window rather than through the address bar
          directly.... if only i knew that 8 hours ago when i was having problems :)

          Comment

          • Chung Leong

            #6
            Re: fopen, fpassthru downloading

            "Steve" <kibblerok@hotm ail.com> wrote in message
            news:pLZec.3001 8$h44.4321879@s tones.force9.ne t...
            [color=blue]
            > i've found a solution albeit unsatisfactory. the script has to be called
            > via a link into a new window rather than through the address bar
            > directly.... if only i knew that 8 hours ago when i was having problems :)[/color]

            The best solution would be to use Apache rewrite, so that the browser thinks
            it's downloading a file in the normal fashion. Worth looking into.


            Comment

            • R. Rajesh Jeba Anbiah

              #7
              Re: fopen, fpassthru downloading

              "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message news:<Sdadnbtff ISNQODdRVn-ig@comcast.com> ...[color=blue]
              > "Steve" <kibblerok@hotm ail.com> wrote in message
              > news:pLZec.3001 8$h44.4321879@s tones.force9.ne t...
              >[color=green]
              > > i've found a solution albeit unsatisfactory. the script has to be called
              > > via a link into a new window rather than through the address bar
              > > directly.... if only i knew that 8 hours ago when i was having problems :)[/color]
              >
              > The best solution would be to use Apache rewrite, so that the browser thinks
              > it's downloading a file in the normal fashion. Worth looking into.[/color]

              I'm skeptical, how the mod_rewrite will help here. The OP says
              about the problem with downloading zip files via script--which we have
              discussed here many times. The download script should be called via
              clicking the link; if it is called directly from browser, it will
              display the binary output.

              --
              http://www.sendmetoindia.com - Send Me to India!
              Email: rrjanbiah-at-Y!com

              Comment

              Working...