PHP-generated link to local file doesn't work when clicked on. Why?

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

    PHP-generated link to local file doesn't work when clicked on. Why?

    I'm running an Apache server on my own computer (Windows XP Pro).

    I wrote a simple PHP script (called test3.php) that I'm running by
    putting the following URL in the address bar of the browser (Firefox)
    ....



    The script generates the following link using the echo statement ...

    <a href="file:///C:/pictures/xyz.jpg"> Picture </a>

    ("C:/pictures/xyz.jpg", as you can guess by now, is an image file on
    my harddrive, but it's not in the document root).

    When I clicked on the link, nothing happened. However, if I
    RIGHT-click on it and select "Copy link location" (which copies the
    URL to the clipboard) and then paste the URL into the address bar of
    the browser, the picture then displays correctly.

    Why did it not work when I clicked on the link the first time, but it
    only worked when I pasted the link to the address bar?

    Is there some special notation/syntax that I need to use to get this
    to work properly?

  • John Dunlop

    #2
    Re: PHP-generated link to local file doesn't work when clicked on. Why?

    wylbur37:
    [color=blue]
    > <a href="file:///C:/pictures/xyz.jpg"> Picture </a>[/color]

    I think - could be wrong - that Firefox doesn't follow file links,
    however they're specified, in resources requested by HTTP. It sits and
    does nothing. Dunno what other browsers do.

    --
    Jock

    Comment

    • wylbur37

      #3
      Re: PHP-generated link to local file doesn't work when clicked on. Why?

      John Dunlop wrote:[color=blue]
      > wylbur37:
      >[color=green]
      > > <a href="file:///C:/pictures/xyz.jpg"> Picture </a>[/color]
      >
      > I think - could be wrong - that Firefox doesn't follow file links,
      > however they're specified, in resources requested by HTTP. It sits and
      > does nothing. Dunno what other browsers do.[/color]

      I have several webpages of HTML code, many of them containing links
      to local files on my harddrive (just like the one show above),
      and they work just fine when the webpage is opened explicitly
      from the browser (and not passed through a local server).

      Comment

      • Oli Filth

        #4
        Re: PHP-generated link to local file doesn't work when clicked on.Why?

        John Dunlop said the following on 26/05/2006 16:02:[color=blue]
        > wylbur37:
        >[color=green]
        >> <a href="file:///C:/pictures/xyz.jpg"> Picture </a>[/color]
        >
        > I think - could be wrong - that Firefox doesn't follow file links,
        > however they're specified, in resources requested by HTTP. It sits and
        > does nothing. Dunno what other browsers do.[/color]

        I'm not sure this makes any sense at all. By definition, a "file://"
        link is not an "http://" link, and so doesn't involve HTTP.

        As for why it doesn't work for the OP, though, I have no idea.



        --
        Oli

        Comment

        • robert

          #5
          Re: PHP-generated link to local file doesn't work when clicked on. Why?


          "John Dunlop" <usenet+2004@jo hn.dunlop.name> wrote in message
          news:1148655758 .303245.293310@ u72g2000cwu.goo glegroups.com.. .
          | wylbur37:
          |
          | > <a href="file:///C:/pictures/xyz.jpg"> Picture </a>
          |
          | I think - could be wrong - that Firefox doesn't follow file links,
          | however they're specified, in resources requested by HTTP. It sits and
          | does nothing. Dunno what other browsers do.

          not sure about that. i'd try taking out the additional / after file before
          thinking that were the case...

          <a href="file://c:/picures/xyz.jpg">file system picture here if clicked</a>


          Comment

          • robert

            #6
            Re: PHP-generated link to local file doesn't work when clicked on. Why?


            "Oli Filth" <catch@olifilth .co.uk> wrote in message
            news:k2Fdg.1306 $zv2.529@newsfe 4-gui.ntli.net...
            | John Dunlop said the following on 26/05/2006 16:02:
            | > wylbur37:
            | >
            | >> <a href="file:///C:/pictures/xyz.jpg"> Picture </a>
            | >
            | > I think - could be wrong - that Firefox doesn't follow file links,
            | > however they're specified, in resources requested by HTTP. It sits and
            | > does nothing. Dunno what other browsers do.
            |
            | I'm not sure this makes any sense at all. By definition, a "file://"
            | link is not an "http://" link, and so doesn't involve HTTP.
            |
            | As for why it doesn't work for the OP, though, I have no idea.

            actually oli, iirc the rfc for href is for a URI and not specifically a
            URL...where the resource could be even something as non-url as a javascript
            function. but i've been wrong before and my memory is not the best.

            i think this doesn't work because of the additional / after file://


            Comment

            • Oli Filth

              #7
              Re: PHP-generated link to local file doesn't work when clicked on.Why?

              robert said the following on 26/05/2006 16:36:[color=blue]
              > "Oli Filth" <catch@olifilth .co.uk> wrote in message
              > news:k2Fdg.1306 $zv2.529@newsfe 4-gui.ntli.net...
              > | John Dunlop said the following on 26/05/2006 16:02:
              > | > wylbur37:
              > | >
              > | >> <a href="file:///C:/pictures/xyz.jpg"> Picture </a>
              > | >
              > | > I think - could be wrong - that Firefox doesn't follow file links,
              > | > however they're specified, in resources requested by HTTP. It sits and
              > | > does nothing. Dunno what other browsers do.
              > |
              > | I'm not sure this makes any sense at all. By definition, a "file://"
              > | link is not an "http://" link, and so doesn't involve HTTP.
              > |
              > | As for why it doesn't work for the OP, though, I have no idea.
              >
              > actually oli, iirc the rfc for href is for a URI and not specifically a
              > URL...where the resource could be even something as non-url as a javascript
              > function.[/color]

              Indeed, I'm aware of that ;) . However, I now realise that I've misread
              John's post, so ignore what I said!


              --
              Oli

              Comment

              • robert

                #8
                Re: PHP-generated link to local file doesn't work when clicked on. Why?


                "Oli Filth" <catch@olifilth .co.uk> wrote in message
                news:InFdg.192$ nc.20@newsfe3-win.ntli.net...
                | robert said the following on 26/05/2006 16:36:
                | > "Oli Filth" <catch@olifilth .co.uk> wrote in message
                | > news:k2Fdg.1306 $zv2.529@newsfe 4-gui.ntli.net...
                | > | John Dunlop said the following on 26/05/2006 16:02:
                | > | > wylbur37:
                | > | >
                | > | >> <a href="file:///C:/pictures/xyz.jpg"> Picture </a>
                | > | >
                | > | > I think - could be wrong - that Firefox doesn't follow file links,
                | > | > however they're specified, in resources requested by HTTP. It sits
                and
                | > | > does nothing. Dunno what other browsers do.
                | > |
                | > | I'm not sure this makes any sense at all. By definition, a "file://"
                | > | link is not an "http://" link, and so doesn't involve HTTP.
                | > |
                | > | As for why it doesn't work for the OP, though, I have no idea.
                | >
                | > actually oli, iirc the rfc for href is for a URI and not specifically a
                | > URL...where the resource could be even something as non-url as a
                javascript
                | > function.
                |
                | Indeed, I'm aware of that ;) . However, I now realise that I've misread
                | John's post, so ignore what I said!

                there's a wink in there, oli...i know you know your stuff many times over.
                that was my gentle supposition more for the op and john dunlop.

                cheers.


                Comment

                • David Haynes

                  #9
                  Re: PHP-generated link to local file doesn't work when clicked on.Why?

                  wylbur37 wrote:[color=blue]
                  > I have several webpages of HTML code, many of them containing links
                  > to local files on my harddrive (just like the one show above),
                  > and they work just fine when the webpage is opened explicitly
                  > from the browser (and not passed through a local server).[/color]

                  Well... wouldn't this lead you to think about the web server blocking
                  the access to those files? I bet C:\pictures is not part of the normal
                  web space for your server. Try a simple page such as:

                  <html>
                  <head></head>
                  <body>
                  <img src="C:/pictures/xyz.jpg">
                  </body>
                  </html>

                  What do your web server logs tell you?

                  -david-

                  Comment

                  • wylbur37

                    #10
                    Re: PHP-generated link to local file doesn't work when clicked on. Why?

                    wylbur37 wrote:[color=blue]
                    > I'm running an Apache server on my own computer (Windows XP Pro).
                    >
                    > I wrote a simple PHP script (called test3.php) that I'm running by
                    > putting the following URL in the address bar of the browser (Firefox)
                    >
                    > http://localhost/test3.php
                    >
                    > The script generates the following link using the echo statement ...
                    >
                    > <a href="file:///C:/pictures/xyz.jpg"> Picture </a>
                    >
                    > ("C:/pictures/xyz.jpg", as you can guess by now, is an image file on
                    > my harddrive, but it's not in the document root).
                    >
                    > When I clicked on the link, nothing happened. However, if I
                    > RIGHT-click on it and select "Copy link location" (which copies the
                    > URL to the clipboard) and then paste the URL into the address bar of
                    > the browser, the picture then displays correctly.
                    >
                    > Why did it not work when I clicked on the link the first time, but it
                    > only worked when I pasted the link to the address bar?
                    >
                    > Is there some special notation/syntax that I need to use to get this
                    > to work properly?[/color]

                    I just tried running the same script while in Internet Explorer
                    and it works.

                    But when I run it in Mozilla 1.4 (suite) or Firefox 1.5,
                    I get the problem described above.

                    Usually it's the other way around (i.e., it doesn't work in Internet
                    Explorer
                    but works in Mozilla or Firefox).

                    It must be because of some setting in the browser.
                    I wonder what it could be.

                    Comment

                    • robert

                      #11
                      Re: PHP-generated link to local file doesn't work when clicked on. Why?

                      | Usually it's the other way around (i.e., it doesn't work in Internet
                      | Explorer
                      | but works in Mozilla or Firefox).
                      |
                      | It must be because of some setting in the browser.
                      | I wonder what it could be.


                      hmmm...that, or the browser/os integration. it could be security permissions
                      on the dir/file compounded with the fact that i.e. probably uses the
                      credentials of the currently logged in user...where ff may not.

                      just a guess though.


                      Comment

                      • wylbur37

                        #12
                        Re: PHP-generated link to local file doesn't work when clicked on. Why?

                        robert wrote:[color=blue]
                        >
                        > ... i'd try taking out the additional / after file before
                        > thinking that were the case...
                        >
                        > <a href="file://c:/picures/xyz.jpg">file system picture here if clicked</a>[/color]

                        I removed one of the slashes from the echo statement,
                        but the interesting thing was that although the HTML that was
                        generated now shows a URL with only two slashes (as verified by
                        View SourceCode), when I hovered the mouse over the link, the status
                        bar (lower left corner of browser) shows it as having three slashes!
                        And when I did a Copy URL to clipboard, it had three slashes!

                        Comment

                        • robert

                          #13
                          Re: PHP-generated link to local file doesn't work when clicked on. Why?


                          "wylbur37" <wylbur37nospam @yahoo.com> wrote in message
                          news:1148659693 .809863.238870@ j33g2000cwa.goo glegroups.com.. .
                          | robert wrote:
                          | >
                          | > ... i'd try taking out the additional / after file before
                          | > thinking that were the case...
                          | >
                          | > <a href="file://c:/picures/xyz.jpg">file system picture here if
                          clicked</a>
                          |
                          | I removed one of the slashes from the echo statement,
                          | but the interesting thing was that although the HTML that was
                          | generated now shows a URL with only two slashes (as verified by
                          | View SourceCode), when I hovered the mouse over the link, the status
                          | bar (lower left corner of browser) shows it as having three slashes!
                          | And when I did a Copy URL to clipboard, it had three slashes!

                          aint that something. actually, i bet it doesn't happen in ie...which could
                          be an indication of why it's not working in ff. have you thought of trying
                          to leave out the 'file://' portion out altogether? try it with
                          c:/pictures/xyz.jpg ... i'm curious if that will fix it. could just be a bug
                          in ff. in which case, you can merrily report it and get your credit for
                          bettering the world! ;^)

                          cheers


                          Comment

                          • Martin Jay

                            #14
                            Re: PHP-generated link to local file doesn't work when clicked on. Why?

                            In message <1148654190.083 042.204000@i40g 2000cwc.googleg roups.com>,
                            wylbur37 <wylbur37nospam @yahoo.com> writes[color=blue]
                            >I'm running an Apache server on my own computer (Windows XP Pro).
                            >
                            >I wrote a simple PHP script (called test3.php) that I'm running by
                            >putting the following URL in the address bar of the browser (Firefox)
                            >...
                            >
                            > http://localhost/test3.php
                            >
                            >The script generates the following link using the echo statement ...
                            >
                            > <a href="file:///C:/pictures/xyz.jpg"> Picture </a>
                            >
                            >("C:/pictures/xyz.jpg", as you can guess by now, is an image file on
                            >my harddrive, but it's not in the document root).
                            >
                            >When I clicked on the link, nothing happened.[/color]

                            It's disabled for security reasons.

                            There's more information about this at:
                            <http://kb.mozillazine. org/Links_to_local_ pages_don't_wor k>
                            --
                            Martin Jay
                            Phone/SMS: +44 7740 191877
                            Fax: +44 870 915 2124

                            Comment

                            • Martin Jay

                              #15
                              Re: PHP-generated link to local file doesn't work when clicked on. Why?

                              In message <gfFdg.13$G82.1 1@fe06.lga>, robert
                              <ab@no.spam-alama-ding-dong> writes[color=blue]
                              >"Oli Filth" <catch@olifilth .co.uk> wrote in message
                              >news:k2Fdg.130 6$zv2.529@newsf e4-gui.ntli.net...
                              >| John Dunlop said the following on 26/05/2006 16:02:
                              >| > wylbur37:
                              >| >
                              >| >> <a href="file:///C:/pictures/xyz.jpg"> Picture </a>[/color]
                              [color=blue]
                              >i think this doesn't work because of the additional / after file://[/color]

                              Your thinking is wrong: file:/// is correct.
                              --
                              Martin Jay
                              Phone/SMS: +44 7740 191877
                              Fax: +44 870 915 2124

                              Comment

                              Working...