how to download a file??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thamood@gmail.com

    #1

    how to download a file??

    Hello guys i'm new in this group but can you help me...i want to create
    a "download files" system - something like "download.c om" - but like
    "download.c om" i dont want the direct link to the file to show i want
    it to be something like :

    "http://www.myhomepage. com/getfile.php?id= 132"

    the idea is to optain the id through the "$_GET" and then get the path
    of the file from the DB ...but then what?the "header()" function wont
    work unless its the 1st function to be called so i cant query the DB
    for the file path then call it!! or is there any other function i can
    use to send the file to the user ???? can any one help me plzzzzzz it's
    drivin me nuts... :))) thnx in advance...

  • Geoff Berrow

    #2
    Re: how to download a file??

    I noticed that Message-ID:
    <1118503366.200 246.157530@f14g 2000cwb.googleg roups.com> from
    thamood@gmail.c om contained the following:
    [color=blue]
    >
    >"http://www.myhomepage. com/getfile.php?id= 132"
    >
    >the idea is to optain the id through the "$_GET" and then get the path
    >of the file from the DB ...but then what?the "header()" function wont
    >work unless its the 1st function to be called so i cant query the DB
    >for the file path then call it!![/color]


    Yes you can. Just make sure you don't out put any html before you call
    it
    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • Janwillem Borleffs

      #3
      Re: how to download a file??

      thamood@gmail.c om wrote:[color=blue]
      > the idea is to optain the id through the "$_GET" and then get the path
      > of the file from the DB ...but then what?the "header()" function wont
      > work unless its the 1st function to be called so i cant query the DB
      > for the file path then call it!! or is there any other function i can
      > use to send the file to the user ???? can any one help me plzzzzzz
      > it's drivin me nuts... :))) thnx in advance...[/color]

      You obviously have miss-interpreted the info on http://www.php.net/header.

      You cannot call header after any output, but you can call as many functions
      you like before calling header() as long as they do not produce any output.

      So, the following will fail:

      <?php
      echo strtoupper("hel lo");
      header("Locatio n: http://www.google.com" );
      ?>

      And the following will succeed:

      <?php
      strtoupper("hel lo");
      header("Locatio n: http://www.google.com" );
      ?>


      JW




      Comment

      • thamood@gmail.com

        #4
        Re: how to download a file??

        Thanx a lot guys for the clarification  I'll try it again and then
        see what happens thanx a lot…

        Comment

        • thamood@gmail.com

          #5
          Re: how to download a file??

          Ahhh...guys sorry to bother ya again.....but what prameters should i
          use with the header so i can download a file...(i'm really a
          newbie)...i thought of useing the "Location :" but i figured it only
          for redirection to some other web site....

          Comment

          • Peter Chant

            #6
            Re: how to download a file??

            thamood@gmail.c om wrote:
            [color=blue]
            > Ahhh...guys sorry to bother ya again.....but what prameters should i
            > use with the header so i can download a file...(i'm really a
            > newbie)...i thought of useing the "Location :" but i figured it only
            > for redirection to some other web site....[/color]

            File name! Something to stop the file getting cached, assuming you don't
            want that. The below code is what I use for RTF files when I generate them.
            Note that there is a problem with Galeon and RTF, so there is a workround
            included in the code. Note the comment above CSV is out of date!

            Pete



            //The output data is generated dynamically, we do not want an old copy stuck
            in a cache.

            //HTTP 1.1
            header("Cache-control: no-store, no-cache, must-revalidate");

            //HTTP 1.0
            header("Pragma: no-cache");

            //Output a csv file, text/plain for a simple plain text file.
            header("Content-Type: application/rtf");

            //Force browser to save it
            //Does not work on Galeon so create a cludge
            $user_agent = $_SERVER["HTTP_USER_AGEN T"];
            if ( $filename != null ) {
            if ( !eregi("galeon" ,$user_agent) ) {
            header('Content-Disposition: attachment; filename="'.$fi lename.'"');
            }
            }


            --

            Comment

            • Hero Wanders

              #7
              Re: how to download a file??

              Hello!
              [color=blue]
              > $user_agent = $_SERVER["HTTP_USER_AGEN T"];
              > if ( $filename != null ) {
              > if ( !eregi("galeon" ,$user_agent) ) {
              > header('Content-Disposition: attachment; filename="'.$fi lename.'"');
              > }
              > }[/color]

              I think the following code is a bit nicer to read:

              <?php
              $user_agent = $_SERVER['HTTP_USER_AGEN T'];

              if (($filename != null) || !eregi('galeon' , $user_agent)) {
              die();
              }

              header('Content-Disposition: attachment; filename="'.$fi lename.'"');
              ?>

              Regards,
              Hero Wanders

              Comment

              • thamood@gmail.com

                #8
                Re: how to download a file??

                helloo many thanx for your replys but the problems still isnt solved
                the problem is i want to duild a download system for "*.fla" files and
                the file's full path is on the DB .. so what i'm tryin to do is to get
                the fill path from the "$_GET[]" then get the fill path from the DB
                then make the download process start at the client side...what
                functions and how will i use them please help me!!! :)

                Comment

                • Peter Chant

                  #9
                  Re: how to download a file??

                  thamood@gmail.c om wrote:
                  [color=blue]
                  > helloo many thanx for your replys but the problems still isnt solved
                  > the problem is i want to duild a download system for "*.fla" files and
                  > the file's full path is on the DB .. so what i'm tryin to do is to get
                  > the fill path from the "$_GET[]" then get the fill path from the DB
                  > then make the download process start at the client side...what
                  > functions and how will i use them please help me!!! :)[/color]

                  Ah, I think my post was halfway there. Maybe you could output the
                  appropriate content type header for your '.fla' file. Then read the file
                  in to a variable (read?) and then use echo to output it.

                  Pete

                  --

                  Comment

                  • thamood@gmail.com

                    #10
                    Re: how to download a file??

                    you know yesit worked thanx a lot man sorry for repeating the quistions
                    :)

                    Comment

                    Working...