Problem downloading binary data

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

    Problem downloading binary data

    Hi all

    I have this script(download .php) which downloads binary data from a
    mysql database.

    <?

    /* SNIP */

    $document=docum ent::singleton( );
    $doc=$document->get_document($ id);

    if (is_object($doc )){
    die;
    }

    header("Content-type: $doc[type]");
    header("Content-length: $doc[size]");
    header("Content-Disposition: attachment; filename=$doc[name]");

    echo($doc['content']);

    exit;

    ?>

    This is called from another page in the
    <a href="download. php?id=4">CLick here to download</a>
    fashion.

    The problem I am experiencing is that the download stop on 64k and then
    the files are obviously corrupted.

    I have checked that I do have the correct size in the db and I am giving
    the correct size in the Content-length header.

    Thanks
    Barry
  • Erwin Moller

    #2
    Re: Problem downloading binary data

    Barry wrote:
    [color=blue]
    > Hi all
    >
    > I have this script(download .php) which downloads binary data from a
    > mysql database.
    >
    > <?
    >
    > /* SNIP */
    >
    > $document=docum ent::singleton( );
    > $doc=$document->get_document($ id);
    >
    > if (is_object($doc )){
    > die;
    > }[/color]

    So if $doc is an object you die?

    Is that what you want?
    I would expect:


    if (is_object($doc )){
    echo "\doc is not an object!";
    exit;
    }

    Regards,
    Erwin Moller
    [color=blue]
    >
    > header("Content-type: $doc[type]");
    > header("Content-length: $doc[size]");
    > header("Content-Disposition: attachment; filename=$doc[name]");
    >
    > echo($doc['content']);
    >
    > exit;
    >
    > ?>
    >
    > This is called from another page in the
    > <a href="download. php?id=4">CLick here to download</a>
    > fashion.
    >
    > The problem I am experiencing is that the download stop on 64k and then
    > the files are obviously corrupted.
    >
    > I have checked that I do have the correct size in the db and I am giving
    > the correct size in the Content-length header.
    >
    > Thanks
    > Barry[/color]

    Comment

    • Erwin Moller

      #3
      Re: Problem downloading binary data

      >[color=blue]
      > if (is_object($doc )){[/color]

      Now I make the same mistake:
      Should be of course:
      if (!is_object($do c)){
      echo "\doc is not an object!";
      exit;
      }[color=blue]
      > echo "\doc is not an object!";
      > exit;
      > }
      >
      > Regards,
      > Erwin Moller[/color]


      Comment

      • Barry

        #4
        Re: Problem downloading binary data

        Erwin Moller wrote:[color=blue]
        > Barry wrote:
        >
        >[color=green]
        >>Hi all
        >>
        >>I have this script(download .php) which downloads binary data from a
        >>mysql database.
        >>
        >><?
        >>
        >>/* SNIP */
        >>
        >>$document=doc ument::singleto n();
        >>$doc=$documen t->get_document($ id);
        >>
        >>if (is_object($doc )){
        >>die;
        >>}[/color]
        >
        >
        > So if $doc is an object you die?
        >
        > Is that what you want?
        > I would expect:
        >
        >
        > if (is_object($doc )){
        > echo "\doc is not an object!";
        > exit;
        > }
        >
        > Regards,
        > Erwin Moller
        >
        >[/color]

        Yes I want it to die.
        The function returns an error object if it fails.
        This means that an error has occured and then I just die.

        If the function returns an array, its found the data.

        This all works for files less than 64k.
        Its only with larger files that the download stops at 64k.
        This is weird bahavior, I think it might be some config on the server.

        Thanks
        Barry
        [color=blue][color=green]
        >>header("Conte nt-type: $doc[type]");
        >>header("Conte nt-length: $doc[size]");
        >>header("Conte nt-Disposition: attachment; filename=$doc[name]");
        >>
        >>echo($doc['content']);
        >>
        >>exit;
        >>
        >>?>
        >>
        >>This is called from another page in the
        >><a href="download. php?id=4">CLick here to download</a>
        >>fashion.
        >>
        >>The problem I am experiencing is that the download stop on 64k and then
        >>the files are obviously corrupted.
        >>
        >>I have checked that I do have the correct size in the db and I am giving
        >>the correct size in the Content-length header.
        >>
        >>Thanks
        >>Barry[/color]
        >
        >[/color]

        Comment

        • Erwin Moller

          #5
          Re: Problem downloading binary data

          Barry wrote:
          [color=blue]
          > Erwin Moller wrote:[color=green]
          >> Barry wrote:
          >>
          >>[color=darkred]
          >>>Hi all
          >>>
          >>>I have this script(download .php) which downloads binary data from a
          >>>mysql database.
          >>>
          >>><?
          >>>
          >>>/* SNIP */
          >>>
          >>>$document=do cument::singlet on();
          >>>$doc=$docume nt->get_document($ id);
          >>>
          >>>if (is_object($doc )){
          >>>die;
          >>>}[/color]
          >>
          >>
          >> So if $doc is an object you die?
          >>
          >> Is that what you want?
          >> I would expect:
          >>
          >>
          >> if (is_object($doc )){
          >> echo "\doc is not an object!";
          >> exit;
          >> }
          >>
          >> Regards,
          >> Erwin Moller
          >>
          >>[/color]
          >
          > Yes I want it to die.
          > The function returns an error object if it fails.
          > This means that an error has occured and then I just die.
          >
          > If the function returns an array, its found the data.
          >
          > This all works for files less than 64k.
          > Its only with larger files that the download stops at 64k.
          > This is weird bahavior, I think it might be some config on the server.[/color]

          Hmm, ok.

          Strange.
          Are you sure your document-singleton is actually delivering the right stuff?
          I mean: the problem could arise earlier than at the moment of delivery.
          And 64K sounds very suspect.

          I would check that part first, just spit out :

          echo htmlentities($d oc['content']);

          Well, that is all I can think of.

          Good luck.

          Regards,
          Erwin Moller
          [color=blue]
          >
          > Thanks
          > Barry
          >[color=green][color=darkred]
          >>>header("Cont ent-type: $doc[type]");
          >>>header("Cont ent-length: $doc[size]");
          >>>header("Cont ent-Disposition: attachment; filename=$doc[name]");
          >>>
          >>>echo($doc['content']);
          >>>
          >>>exit;
          >>>
          >>>?>
          >>>
          >>>This is called from another page in the
          >>><a href="download. php?id=4">CLick here to download</a>
          >>>fashion.
          >>>
          >>>The problem I am experiencing is that the download stop on 64k and then
          >>>the files are obviously corrupted.
          >>>
          >>>I have checked that I do have the correct size in the db and I am giving
          >>>the correct size in the Content-length header.
          >>>
          >>>Thanks
          >>>Barry[/color]
          >>
          >>[/color][/color]

          Comment

          • Barry

            #6
            Re: Problem downloading binary data

            Erwin Moller wrote:[color=blue]
            > Barry wrote:
            >
            >[color=green]
            >>Erwin Moller wrote:
            >>[color=darkred]
            >>>Barry wrote:
            >>>
            >>>
            >>>
            >>>>Hi all
            >>>>
            >>>>I have this script(download .php) which downloads binary data from a
            >>>>mysql database.
            >>>>
            >>>><?
            >>>>
            >>>>/* SNIP */
            >>>>
            >>>>$document=d ocument::single ton();
            >>>>$doc=$docum ent->get_document($ id);
            >>>>
            >>>>if (is_object($doc )){
            >>>>die;
            >>>>}
            >>>
            >>>
            >>>So if $doc is an object you die?
            >>>
            >>>Is that what you want?
            >>>I would expect:
            >>>
            >>>
            >>>if (is_object($doc )){
            >>> echo "\doc is not an object!";
            >>> exit;
            >>>}
            >>>
            >>>Regards,
            >>>Erwin Moller
            >>>
            >>>[/color]
            >>
            >>Yes I want it to die.
            >>The function returns an error object if it fails.
            >>This means that an error has occured and then I just die.
            >>
            >>If the function returns an array, its found the data.
            >>
            >>This all works for files less than 64k.
            >>Its only with larger files that the download stops at 64k.
            >>This is weird bahavior, I think it might be some config on the server.[/color]
            >
            >
            > Hmm, ok.
            >
            > Strange.
            > Are you sure your document-singleton is actually delivering the right stuff?
            > I mean: the problem could arise earlier than at the moment of delivery.
            > And 64K sounds very suspect.
            >
            > I would check that part first, just spit out :
            >
            > echo htmlentities($d oc['content']);
            >
            > Well, that is all I can think of.
            >
            > Good luck.
            >
            > Regards,
            > Erwin Moller
            >
            >[/color]

            thanks for the help.
            yes, I get the correct data.
            when I dump the array all is there.

            also, docs and images below 64k work fine.

            strange one this.
            [color=blue][color=green]
            >>Thanks
            >>Barry
            >>
            >>[color=darkred]
            >>>>header("Con tent-type: $doc[type]");
            >>>>header("Con tent-length: $doc[size]");
            >>>>header("Con tent-Disposition: attachment; filename=$doc[name]");
            >>>>
            >>>>echo($doc['content']);
            >>>>
            >>>>exit;
            >>>>
            >>>>?>
            >>>>
            >>>>This is called from another page in the
            >>>><a href="download. php?id=4">CLick here to download</a>
            >>>>fashion.
            >>>>
            >>>>The problem I am experiencing is that the download stop on 64k and then
            >>>>the files are obviously corrupted.
            >>>>
            >>>>I have checked that I do have the correct size in the db and I am giving
            >>>>the correct size in the Content-length header.
            >>>>
            >>>>Thanks
            >>>>Barry
            >>>
            >>>[/color][/color]
            >[/color]

            Comment

            • Jim Michaels

              #7
              Re: Problem downloading binary data

              I have seen cutoff problems in other posts in trying to use fread() with
              chunks larger than about 8K.
              is that what you are using in your method?

              "Barry" <b@b.com> wrote in message news:dr7v5h$ji9 $1@ctb-nnrp2.saix.net. ..[color=blue]
              > Erwin Moller wrote:[color=green]
              >> Barry wrote:
              >>
              >>[color=darkred]
              >>>Erwin Moller wrote:
              >>>
              >>>>Barry wrote:
              >>>>
              >>>>
              >>>>
              >>>>>Hi all
              >>>>>
              >>>>>I have this script(download .php) which downloads binary data from a
              >>>>>mysql database.
              >>>>>
              >>>>><?
              >>>>>
              >>>>>/* SNIP */
              >>>>>
              >>>>>$document= document::singl eton();
              >>>>>$doc=$docu ment->get_document($ id);
              >>>>>
              >>>>>if (is_object($doc )){
              >>>>>die;
              >>>>>}
              >>>>
              >>>>
              >>>>So if $doc is an object you die?
              >>>>
              >>>>Is that what you want?
              >>>>I would expect:
              >>>>
              >>>>
              >>>>if (is_object($doc )){
              >>>> echo "\doc is not an object!";
              >>>> exit;
              >>>>}
              >>>>
              >>>>Regards,
              >>>>Erwin Moller
              >>>>
              >>>>
              >>>
              >>>Yes I want it to die.
              >>>The function returns an error object if it fails.
              >>>This means that an error has occured and then I just die.
              >>>
              >>>If the function returns an array, its found the data.
              >>>
              >>>This all works for files less than 64k.
              >>>Its only with larger files that the download stops at 64k.
              >>>This is weird bahavior, I think it might be some config on the server.[/color]
              >>
              >>
              >> Hmm, ok.
              >>
              >> Strange.
              >> Are you sure your document-singleton is actually delivering the right
              >> stuff?
              >> I mean: the problem could arise earlier than at the moment of delivery.
              >> And 64K sounds very suspect.
              >>
              >> I would check that part first, just spit out :
              >>
              >> echo htmlentities($d oc['content']);
              >>
              >> Well, that is all I can think of.
              >>
              >> Good luck.
              >>
              >> Regards,
              >> Erwin Moller
              >>
              >>[/color]
              >
              > thanks for the help.
              > yes, I get the correct data.
              > when I dump the array all is there.
              >
              > also, docs and images below 64k work fine.
              >
              > strange one this.
              >[color=green][color=darkred]
              >>>Thanks
              >>>Barry
              >>>
              >>>
              >>>>>header("Co ntent-type: $doc[type]");
              >>>>>header("Co ntent-length: $doc[size]");
              >>>>>header("Co ntent-Disposition: attachment; filename=$doc[name]");
              >>>>>
              >>>>>echo($do c['content']);
              >>>>>
              >>>>>exit;
              >>>>>
              >>>>>?>
              >>>>>
              >>>>>This is called from another page in the
              >>>>><a href="download. php?id=4">CLick here to download</a>
              >>>>>fashion.
              >>>>>
              >>>>>The problem I am experiencing is that the download stop on 64k and then
              >>>>>the files are obviously corrupted.
              >>>>>
              >>>>>I have checked that I do have the correct size in the db and I am
              >>>>>giving
              >>>>>the correct size in the Content-length header.
              >>>>>
              >>>>>Thanks
              >>>>>Barry
              >>>>
              >>>>[/color]
              >>[/color][/color]


              Comment

              Working...