LOCALHOST webserver not behaving same as remote server

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

    LOCALHOST webserver not behaving same as remote server


    I'm developing a web site, which I test first on my PC (http://localhost/...) and then upload to the
    web site on the internet when ok.

    I have a little bit of PHP code (in file download.php) which I use to force the Save dialogue when I
    want the user to download a PDF file. The hyperlink looks like:-



    This PHP works *fine* ... on the internet site - but *not* locally!!!

    On the localhost, instead of prompting to download the PDF file, it prompts to download the PHP file
    itself!

    What do I need to do / configure (and HOW and WHERE please) to get this to work locally??

    My local web server is Apache 2, and I'm using PHP 4.

    The PHP code is just:-
    <?PHP
    header("Content-type: application/octet-stream");
    header("Content-Length: ".filesize($fil ename));
    header("Content-Disposition: attachment; filename=$filen ame");
    $fp = fopen($filename , 'rb');
    fpassthru($fp);
    fclose($fp);
    ?>

    Thanks!




  • Gary Petersen

    #2
    Re: LOCALHOST webserver not behaving same as remote server

    (dolphin talk) eeeeeekkkkkk squueeeekkkkk Richard White
    eeeeeiiiiiiikkk kkkkk squeeeeekk Fri, 12 Sep 2003 01:25:05 -0500,
    eeeeeiiiiiiieee eeekkkk eeeeekkkkkk eeiiikkkk
    <bjrotm$mcc2a$1 @ID-162217.news.uni-berlin.de>:

    [color=blue]
    > [...]
    > This PHP works *fine* ... on the internet site - but *not* locally!!!
    >
    > On the localhost, instead of prompting to download the PDF file, it
    > prompts to download the PHP file itself!
    >[/color]

    Is PHP enabled on your web server? Can you get
    a simple "hello world" PHP script executed?

    (Folloups set to comp.lang.php)

    Comment

    • Richard White

      #3
      Re: LOCALHOST webserver not behaving same as remote server


      "Gary Petersen" <garyp1492@remo ve.meearthlink. invalid> wrote in message
      news:pan.2003.0 9.12.07.25.03.6 02372.1257@REMO VE.MEearthlink. INVALID...[color=blue]
      > (dolphin talk) eeeeeekkkkkk squueeeekkkkk Richard White
      > eeeeeiiiiiiikkk kkkkk squeeeeekk Fri, 12 Sep 2003 01:25:05 -0500,
      > eeeeeiiiiiiieee eeekkkk eeeeekkkkkk eeiiikkkk
      > <bjrotm$mcc2a$1 @ID-162217.news.uni-berlin.de>:
      >
      >[color=green]
      > > [...]
      > > This PHP works *fine* ... on the internet site - but *not* locally!!!
      > >
      > > On the localhost, instead of prompting to download the PDF file, it
      > > prompts to download the PHP file itself!
      > >[/color]
      >
      > Is PHP enabled on your web server? Can you get
      > a simple "hello world" PHP script executed?[/color]

      Yes - my simple test.php script to return current date in browser window works fine.


      Comment

      • Gary Petersen

        #4
        Re: LOCALHOST webserver not behaving same as remote server

        (dolphin talk) eeeeeekkkkkk squueeeekkkkk Richard White
        eeeeeiiiiiiikkk kkkkk squeeeeekk Fri, 12 Sep 2003 01:25:05 -0500,
        eeeeeiiiiiiieee eeekkkk eeeeekkkkkk eeiiikkkk
        <bjrotm$mcc2a$1 @ID-162217.news.uni-berlin.de>:

        [color=blue]
        > I'm developing a web site, which I test first on my PC
        > (http://localhost/...) and then upload to the web site on the internet
        > when ok.
        >
        > I have a little bit of PHP code (in file download.php) which I use to
        > force the Save dialogue when I want the user to download a PDF file.
        > The hyperlink looks like:-
        >
        > http://localhost/download.php?filename=my_pdf_file.pdf
        >
        > This PHP works *fine* ... on the internet site - but *not* locally!!!
        >
        > On the localhost, instead of prompting to download the PDF file, it
        > prompts to download the PHP file
        > itself!
        >
        > What do I need to do / configure (and HOW and WHERE please) to get this
        > to work locally??
        >
        > My local web server is Apache 2, and I'm using PHP 4.
        >
        > The PHP code is just:-
        > <?PHP
        > header("Content-type: application/octet-stream");
        > header("Content-Length: ".filesize($fil ename));
        > header("Content-Disposition: attachment; filename=$filen ame");
        > $fp = fopen($filename , 'rb');
        > fpassthru($fp);
        > fclose($fp);
        > ?>[/color]

        You don't need to close the file handle after using fpassthru() since it
        is already closed. In fact, attempting to close it causes an error
        which appends error message text to the end of your HTTP response.

        Nonetheless, your script should work, and it did on my system. I'm using
        Apache 1.3 and PHP 4.0.5. I used Lynx, Firebird and Amaya to
        download the file.

        Maybe it's a browser issue; read RFC 2616 section 19. My interpretation
        of that section is that the "filename=$file name" part provides
        only a suggested filename--not a required one. I believe that
        browsers are free to ignore it if they want to.

        Comment

        • Richard White

          #5
          Re: LOCALHOST webserver not behaving same as remote server


          "Gary Petersen" <garyp1492@remo ve.meearthlink. invalid> wrote in message
          news:pan.2003.0 9.12.18.19.13.7 07599.297@REMOV E.MEearthlink.I NVALID...[color=blue]
          > (dolphin talk) eeeeeekkkkkk squueeeekkkkk Richard White
          > eeeeeiiiiiiikkk kkkkk squeeeeekk Fri, 12 Sep 2003 01:25:05 -0500,
          > eeeeeiiiiiiieee eeekkkk eeeeekkkkkk eeiiikkkk
          > <bjrotm$mcc2a$1 @ID-162217.news.uni-berlin.de>:[/color]
          [...snipped...][color=blue]
          > Maybe it's a browser issue; read RFC 2616 section 19. My interpretation
          > of that section is that the "filename=$file name" part provides
          > only a suggested filename--not a required one. I believe that
          > browsers are free to ignore it if they want to.[/color]

          I'm using the same browser on my PC. Some sessions to localhost and others to the internet site.



          Comment

          Working...