Returning a file to browser via php

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

    Returning a file to browser via php

    Hello all.

    I need to be able to "send, or stream" a file to the client browser
    using PHP code. This is the scenario.


    The user clicks a link on a page (after logging in to the site). I
    need to have my PHP code return a document -a Word document file, let's
    say - to the browser for display. However, the document is not in the
    public WWW folder. For security reasons, it is on another drive on the
    same machine.
    I need to have the php code return the file to the browser so that I
    can wrap security code around this process.

    Thanks in advance, any insight is greatly appreciated !

  • Peter Albertsson

    #2
    Re: Returning a file to browser via php

    <?php
    header('Content-Type: application/msword');
    header('Content-Disposition: attachment; filename=filena me.doc');
    readfile('/not/in/web/root/word.doc');
    ?>

    Best regards,

    Peter Albertsson

    "SLOGIC" <wholesale@bi z-spot.com> wrote in message
    news:1111503343 .778866.199900@ l41g2000cwc.goo glegroups.com.. .[color=blue]
    > Hello all.
    >
    > I need to be able to "send, or stream" a file to the client browser
    > using PHP code. This is the scenario.
    >
    >
    > The user clicks a link on a page (after logging in to the site). I
    > need to have my PHP code return a document -a Word document file, let's
    > say - to the browser for display. However, the document is not in the
    > public WWW folder. For security reasons, it is on another drive on the
    > same machine.
    > I need to have the php code return the file to the browser so that I
    > can wrap security code around this process.
    >
    > Thanks in advance, any insight is greatly appreciated !
    >[/color]


    Comment

    • Bosconian

      #3
      Re: Returning a file to browser via php

      "SLOGIC" <wholesale@bi z-spot.com> wrote in message
      news:1111503343 .778866.199900@ l41g2000cwc.goo glegroups.com.. .[color=blue]
      > Hello all.
      >
      > I need to be able to "send, or stream" a file to the client browser
      > using PHP code. This is the scenario.
      >
      >
      > The user clicks a link on a page (after logging in to the site). I
      > need to have my PHP code return a document -a Word document file, let's
      > say - to the browser for display. However, the document is not in the
      > public WWW folder. For security reasons, it is on another drive on the
      > same machine.
      > I need to have the php code return the file to the browser so that I
      > can wrap security code around this process.
      >
      > Thanks in advance, any insight is greatly appreciated !
      >[/color]

      You might be making this more complicated than it needs to be.

      You already have the physical files stored outside the web server root.
      Authenticate the user and give them a link to download the file.


      Comment

      Working...