Looking for a script to download pdf file from server

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

    #1

    Looking for a script to download pdf file from server

    Hi,

    I am looking for a script that will download a pdf file from my server without
    opening it in IE. I want peeople to be able to simply download the file and
    store it in a location on their PC. Any help greatly appreciated.

    Regards
    Dynamo

  • Rik

    #2
    Re: Looking for a script to download pdf file from server

    Dynamo wrote:[color=blue]
    > Hi,
    >
    > I am looking for a script that will download a pdf file from my
    > server without opening it in IE. I want peeople to be able to simply
    > download the file and store it in a location on their PC. Any help
    > greatly appreciated.[/color]

    header('Content-disposition: attachment');

    Grtz,
    --
    Rik Wasmus


    Comment

    • Dynamo

      #3
      Re: Looking for a script to download pdf file from server

      Many thanks but somehow I dont think that snippet of code on its own will do
      what I want. I was looking for the complete code. I have tried the following but
      it failed miserably. What am I doing wrong?

      <?php
      $dir_name = "/books/";
      $file = "downloadtest.p df";

      $content = file_get_conten ts($dir_name . $file);

      header('Content-Type: pdf');
      header('Content-Length: ' . filesize($dir_n ame . $file));
      header('Content-Disposition: 'attachment');
      echo $content;
      ?>

      Regards
      Dynamo


      In article <e4v2b9$phg$1@n etlx020.civ.utw ente.nl>, Rik says...[color=blue]
      >
      >Dynamo wrote:[color=green]
      >> Hi,
      >>
      >> I am looking for a script that will download a pdf file from my
      >> server without opening it in IE. I want peeople to be able to simply
      >> download the file and store it in a location on their PC. Any help
      >> greatly appreciated.[/color]
      >
      >header('Conten t-disposition: attachment');
      >
      >Grtz,[/color]

      Comment

      • Rik

        #4
        Re: Looking for a script to download pdf file from server

        Dynamo wrote:[color=blue]
        > Many thanks but somehow I dont think that snippet of code on its own
        > will do what I want. I was looking for the complete code. I have
        > tried the following but it failed miserably. What am I doing wrong?
        >
        > <?php
        > $dir_name = "/books/";
        > $file = "downloadtest.p df";
        >
        > $content = file_get_conten ts($dir_name . $file);
        >
        > header('Content-Type: pdf');
        > header('Content-Length: ' . filesize($dir_n ame . $file));
        > header('Content-Disposition: 'attachment');
        > echo $content;[/color]


        1. Turn on error reporting, if this is you script, it will tell you some
        interesting things.
        2. Is /books/ in your root? If not, you can't refer to it like this. Does
        content indeed hold the file, or just 'false"?

        Also:
        it's header('Content-type: application/pdf');


        The exact syntax is in the php-manual as an example for header...


        header('Content-type: application/pdf');
        header('Content-Disposition: attachment; filename="name_ give_to_user.pd f"');
        readfile('/path/to/original.pdf');

        Grtz,
        --
        Rik Wasmus


        Comment

        • strawberry

          #5
          Re: Looking for a script to download pdf file from server

          Why not just add a note on screen saying something like "User of IE
          right-click and then hit 'Save Target As..' to download without opening"

          Comment

          • Dynamo

            #6
            Re: Looking for a script to download pdf file from server

            Good point. I guess it's a matter of personal preference. IMHO I don't think
            that looks very professional on a company site. Sure OK for a personal site to
            download music etc etc but I don't see many company sites doing that. They
            mostly have a "Download here" type of button.

            Kind Regards
            Dynamo

            In article <1148397189.389 857.164520@j55g 2000cwa.googleg roups.com>, strawberry
            says...[color=blue]
            >
            >Why not just add a note on screen saying something like "User of IE
            >right-click and then hit 'Save Target As..' to download without opening"
            >[/color]

            Comment

            • Christopher Vogt

              #7
              Re: Looking for a script to download pdf file from server

              > Good point. I guess it's a matter of personal preference. IMHO I don't think[color=blue]
              > that looks very professional on a company site. Sure OK for a personal site to
              > download music etc etc but I don't see many company sites doing that. They
              > mostly have a "Download here" type of button.[/color]

              I would say IT IS more professional to give a "right click to
              download"-hint as it it showing the user how to do it right. However a
              simple link is more convenient and supports unexperienced users. I
              implemented that once with fpdf (fpdf.org). Its method Output() has a
              parameter that exactly covers the task (more on
              http://www.fpdf.org/en/doc/output.htm). I also remember that I read the
              implementation and believe to remember that they worked with some dummy
              Content-Disposition. You can either do that as well or create a simple
              instance of fpdf and look for the header it sends with with one or the
              other option. Try telnet or HTTP Live Headers (Firefox Extension) to see
              the headers the server sends.

              Comment

              • John Dunlop

                #8
                Re: Looking for a script to download pdf file from server

                Dynamo:
                [color=blue]
                > [strawberry:]
                >[color=green]
                > > Why not just add a note on screen saying something like "User of IE
                > > right-click and then hit 'Save Target As..' to download without opening"[/color]
                >
                > Good point. I guess it's a matter of personal preference. IMHO I don't think
                > that looks very professional on a company site. Sure OK for a personal site to
                > download music etc etc but I don't see many company sites doing that. They
                > mostly have a "Download here" type of button.[/color]

                If you want to copy a particular website, copy it. Look at what it
                says to users, look at what it says to user-agents, send requests, look
                at responses.

                While strawberry's suggestion would violate the general principle
                that says Don't Mention the Mechanics, I regard it as less harmful than
                the server-side jiggery-pokery proposed upthread.

                --
                Jock

                Comment

                • strawberry

                  #9
                  Re: Looking for a script to download pdf file from server

                  Oops, what have I started...?

                  Comment

                  • Dynamo

                    #10
                    Attn: Rik Re: Looking for a script to download pdf file from server

                    Many thanks. That does exactly what I want. I already looked at that page in the
                    php manual and the example code is quite a way down the page. Guess I must have
                    passed it by.

                    Regards
                    Dynamo

                    In article <e4v8lo$7u1$1@n etlx020.civ.utw ente.nl>, Rik says...[color=blue]
                    >1. Turn on error reporting, if this is you script, it will tell you some
                    >interesting things.
                    >2. Is /books/ in your root? If not, you can't refer to it like this. Does
                    >content indeed hold the file, or just 'false"?
                    >
                    >Also:
                    >it's header('Content-type: application/pdf');
                    >
                    >
                    >The exact syntax is in the php-manual as an example for header...
                    >http://nl3.php.net/en/header
                    >
                    >header('Conten t-type: application/pdf');
                    >header('Conten t-Disposition: attachment; filename="name_ give_to_user.pd f"');
                    >readfile('/path/to/original.pdf');
                    >
                    >Grtz,[/color]

                    Comment

                    • NC

                      #11
                      Re: Looking for a script to download pdf file from server

                      Dynamo wrote:[color=blue]
                      >
                      > I am looking for a script that will download a pdf file from my server
                      > without opening it in IE.[/color]

                      There is no guarantee that this will ever happen. IE ignores
                      "Content-Dispositoin:" headers completely.

                      Cheers,
                      NC

                      Comment

                      • John Dunlop

                        #12
                        Re: Looking for a script to download pdf file from server

                        NC:
                        [color=blue]
                        > IE ignores "Content-Dispositoin:" headers completely.[/color]

                        Given a choice between always ignoring it or always following it, I
                        think always ignoring it is preferable, not only because it isn't part
                        of HTTP but also because always following it would grant undue power to
                        the publisher. But I'd like to think that a user-agent could treat
                        Content-Disposition as it was intended, as nothing more than a
                        suggestion. Nothing stops a user-agent from making the publisher's
                        'desired presentation' - be it the same as or different to the
                        user-agent's normal mode of presentation - *known* to the user, without
                        making it obligatory.

                        </rant>

                        --
                        Jock

                        Comment

                        Working...