can src attribute of an image tag refer to a unc path?

Discussion in 'HTML' started by TheUsenetReader@gmail.com, Dec 13, 2007.

  1. Guest

    can the src attribute of an image tag refer to a unc path? i.e., \
    \servername\folder\mypict.jpg.

    the html page will only be viewed internally by employees who all have
    access to the server.

    is there any way to refer to the image stored on \\servername\folder
    \mypict.jpg?
     
    , Dec 13, 2007
    #1
    1. Advertising

  2. rf Guest

    <> wrote in message
    news:...
    > can the src attribute of an image tag refer to a unc path? i.e., \
    > \servername\folder\mypict.jpg.


    Did you try it?

    --
    Richard.
     
    rf, Dec 13, 2007
    #2
    1. Advertising

  3. Andy Dingley Guest

    On 13 Dec, 12:58, wrote:
    > can the src attribute of an image tag refer to a unc path?


    There's a "file:" protocol permitted in the URI specification that can
    be used to wrap up a UNC.

    Support and real-time usefulness is too poor for the web, but it's
    enough for intranet work.
     
    Andy Dingley, Dec 13, 2007
    #3
  4. TheUsenetReader wrote:

    > can the src attribute of an image tag refer to a unc path? i.e., \
    > \servername\folder\mypict.jpg.


    <img src="file://\\servername\share\example.jpeg">

    should work in most Windows browsers.

    --
    Toby A Inkster BSc (Hons) ARCS
    [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
    [OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 6 days, 2:29.]

    Sharing Music with Apple iTunes
    http://tobyinkster.co.uk/blog/2007/11/28/itunes-sharing/
     
    Toby A Inkster, Dec 13, 2007
    #4
  5. Bergamot Guest

    Toby A Inkster wrote:
    >
    > <img src="file://\\servername\share\example.jpeg">
    >
    > should work in most Windows browsers.


    I wouldn't expect back slashes to work in browsers other than IE,
    Windows or not.

    Shouldn't a file: URI use the full path, including drive letter?
    <img src="file:///d:/path/to/example.jpeg">

    --
    Berg
     
    Bergamot, Dec 13, 2007
    #5
  6. Bergamot wrote:

    > Shouldn't a file: URI use the full path, including drive letter? <img
    > src="file:///d:/path/to/example.jpeg">


    "Drive letter"? What's a "drive letter"?!

    Seriously, although file:// URLs need to include a full path, not all full
    paths contain a drive letter -- most operating systems don't even have
    such a concept.

    UNC paths are an example of a path that does not contain a drive letter.

    I missed out a slash in my original example. Should be:

    <img src="file:///\\servername\share\example.jpeg">

    > I wouldn't expect back slashes to work in browsers other than IE,
    > Windows or not.


    Backslashes should work, as they are the preferred path separator
    character on Windows. However, as Windows usually supports a forward slash
    as an alternative, they should work too:

    <img src="file://///servername/share/example.jpeg">

    Yes, that's right: five slashes in a row. The first two are part of the
    protocol indicator ("file://") then there is supposed to be a host name
    (no this is not the file server host name, but should be the host name
    which the file should be accessed from. i.e. localhost, which is the
    default, so can be left blank!) then another slash. Then the UNC path
    starts, which explains the last two slashes, as all UNC paths start with
    two slashes.

    It's probably most readable this way:

    <img src="file://localhost/\\servername\share\example.jpeg">

    --
    Toby A Inkster BSc (Hons) ARCS
    [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
    [OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 6 days, 3:24.]

    Sharing Music with Apple iTunes
    http://tobyinkster.co.uk/blog/2007/11/28/itunes-sharing/
     
    Toby A Inkster, Dec 13, 2007
    #6
  7. Bergamot wrote:
    > Toby A Inkster wrote:
    >> <img src="file://\\servername\share\example.jpeg">
    >>
    >> should work in most Windows browsers.

    >
    > I wouldn't expect back slashes to work in browsers other than IE,
    > Windows or not.
    >
    > Shouldn't a file: URI use the full path, including drive letter?
    > <img src="file:///d:/path/to/example.jpeg">


    Does the file: protocol apply only to Microsoft designations for locally
    mapped drives? \\servername\share\example.jpeg IS a full path as, on a
    Unix system, /usr/~jperson/example.jpeg would be.
     
    Harlan Messinger, Dec 13, 2007
    #7
  8. Jukka K. Korpela, Dec 13, 2007
    #8
  9. Guest

    On Dec 13, 5:12 am, "rf" <> wrote:
    > <> wrote in message
    >
    > news:...
    >
    > > can the src attribute of an image tag refer to a unc path? i.e., \
    > > \servername\folder\mypict.jpg.

    >
    > Did you try it?
    >
    > --
    > Richard.


    yes. it didn't work. (using windows xp and firefox).
    the "file://" suggested by other posters worked.
     
    , Dec 13, 2007
    #9
  10. Guest

    On Dec 13, 9:06 am, Toby A Inkster <>
    wrote:
    > Bergamot wrote:
    > > Shouldn't a file: URI use the full path, including drive letter? <img
    > > src="file:///d:/path/to/example.jpeg">

    >
    > "Drive letter"? What's a "drive letter"?!
    >
    > Seriously, although file:// URLs need to include a full path, not all full
    > paths contain a drive letter -- most operating systems don't even have
    > such a concept.
    >
    > UNC paths are an example of a path that does not contain a drive letter.
    >
    > I missed out a slash in my original example. Should be:
    >
    > <img src="file:///\\servername\share\example.jpeg">
    >
    > > I wouldn't expect back slashes to work in browsers other than IE,
    > > Windows or not.

    >
    > Backslashes should work, as they are the preferred path separator
    > character on Windows. However, as Windows usually supports a forward slash
    > as an alternative, they should work too:
    >
    > <img src="file://///servername/share/example.jpeg">
    >
    > Yes, that's right: five slashes in a row. The first two are part of the
    > protocol indicator ("file://") then there is supposed to be a host name
    > (no this is not the file server host name, but should be the host name
    > which the file should be accessed from. i.e. localhost, which is the
    > default, so can be left blank!) then another slash. Then the UNC path
    > starts, which explains the last two slashes, as all UNC paths start with
    > two slashes.
    >
    > It's probably most readable this way:
    >
    > <img src="file://localhost/\\servername\share\example.jpeg">
    >


    thanks! that works...

    but the localhost part is confusing.
    in what case would the host name (the host from which the file should
    be accessed from) be anything else but localhost?
     
    , Dec 13, 2007
    #10
  11. Bergamot Guest

    Toby A Inkster wrote:
    > Bergamot wrote:
    >
    >> Shouldn't a file: URI use the full path, including drive letter? <img
    >> src="file:///d:/path/to/example.jpeg">

    >
    > What's a "drive letter"?!


    Of course drive letters are a Windows thing, but the reference was to a
    Windows network, so it matters not what other OS's do or don't do. Drive
    letters certainly can apply to a file: URI on Windows.

    > UNC paths are an example of a path that does not contain a drive letter.


    I missed the part about UNC altogether, but no matter since I hadn't
    heard of it before anyhow. Your explanation didn't really help, but I
    found a couple others that did.

    I am now enlightened.

    --
    Berg
     
    Bergamot, Dec 13, 2007
    #11
  12. TheUsenetReader wrote:

    > in what case would the host name (the host from which the file should be
    > accessed from) be anything else but localhost?


    "file://foobar.example.com/c:/autoexec.bat" means "the file
    'c:/autoexec.bat' on the computer 'foobar.example.com'".

    The "file://" protocol doesn't specify any method by which you can
    *obtain* a copy of that file -- it's just an indicator of which file
    you mean. If you want a copy of "file://foobar.example.com/c:/
    autoexec.bat", then you might need to walk over to the physical
    foobar.example.com computer and copy it onto your USB keyring!

    --
    Toby A Inkster BSc (Hons) ARCS
    [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
    [OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 6 days, 19:27.]

    Sharing Music with Apple iTunes
    http://tobyinkster.co.uk/blog/2007/11/28/itunes-sharing/
     
    Toby A Inkster, Dec 14, 2007
    #12
  13. Toby A Inkster wrote:
    > TheUsenetReader wrote:
    >
    >> in what case would the host name (the host from which the file should be
    >> accessed from) be anything else but localhost?

    >
    > "file://foobar.example.com/c:/autoexec.bat" means "the file
    > 'c:/autoexec.bat' on the computer 'foobar.example.com'".


    It might look like it means that (depending on what "means" means) but
    it won't have that effect. On the Microsoft OSes the only way to access
    files on other computers is through shares. If the root of the C drive
    on foobar is shared as C$ then the URL would be

    file://foobar.example.com/c$/autoexec.bat

    > The "file://" protocol doesn't specify any method by which you can
    > *obtain* a copy of that file -- it's just an indicator of which file
    > you mean. If you want a copy of "file://foobar.example.com/c:/
    > autoexec.bat", then you might need to walk over to the physical
    > foobar.example.com computer and copy it onto your USB keyring!


    Yes, in theory the result of clicking a link to an autoexec.bat in your
    browser would be not to download it but to execute it.
     
    Harlan Messinger, Dec 14, 2007
    #13
  14. wrote:
    > On Dec 13, 5:12 am, "rf" <> wrote:
    >> <> wrote in message
    >>
    >> news:...
    >>
    >>> can the src attribute of an image tag refer to a unc path? i.e., \
    >>> \servername\folder\mypict.jpg.

    >> Did you try it?
    >>
    >> --
    >> Richard.

    >
    > yes. it didn't work. (using windows xp and firefox).
    > the "file://" suggested by other posters worked.


    Yes, "\" is a M$ thing. You need you slashes to go in the other
    direction and use the "file://" protocol for web browser support.


    <img src="file://///servername/folder/mypict.jpg" alt="my pict">


    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
     
    Jonathan N. Little, Dec 14, 2007
    #14
  15. Harlan Messinger wrote:
    > Toby A Inkster wrote:
    >> TheUsenetReader wrote:
    >>
    >>> in what case would the host name (the host from which the file should
    >>> be accessed from) be anything else but localhost?

    >>
    >> "file://foobar.example.com/c:/autoexec.bat" means "the file
    >> 'c:/autoexec.bat' on the computer 'foobar.example.com'".

    >
    > It might look like it means that (depending on what "means" means) but
    > it won't have that effect. On the Microsoft OSes the only way to access
    > files on other computers is through shares. If the root of the C drive
    > on foobar is shared as C$ then the URL would be
    >
    > file://foobar.example.com/c$/autoexec.bat


    No, that is a completely different URL.

    file://foobar.example.com/c$/autoexec.bat *DOES NOT MEAN* to access share
    "C$" on server "foobar.example.com".

    The correct way to reference "C:\AUTOEXEC.BAT" on foobar.example.com is:

    file://foobar.example.com/c:/autoexec.bat

    Note that clicking on such a link won't normally *do* anything, but URLs
    don't have to do anything -- consider URNs.

    --
    Toby A Inkster BSc (Hons) ARCS
    [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
    [OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 7 days, 2:08.]

    Sharing Music with Apple iTunes
    http://tobyinkster.co.uk/blog/2007/11/28/itunes-sharing/
     
    Toby A Inkster, Dec 14, 2007
    #15
  16. Harlan Messinger wrote:

    > If the root of the C drive on foobar is shared as C$ then the URL would
    > be
    >
    > file://foobar.example.com/c$/autoexec.bat


    Further to my other post... no it is not. The way to reference the file
    "autoexec.bat" shared using the Windows share "\\foobar.example.com\c$"
    would be any one of these:

    file://localhost/\\foobar.example.com\c$\autoexec.bat
    file://localhost///foobar.example.com/c$/autoexec.bat
    file:///\\foobar.example.com\c$\autoexec.bat
    file://///foobar.example.com/c$/autoexec.bat

    Depending on whether you want to leave out the default "localhost" part,
    and on which types of slashes you wish to use for the Windows path.

    --
    Toby A Inkster BSc (Hons) ARCS
    [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
    [OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 7 days, 2:11.]

    Sharing Music with Apple iTunes
    http://tobyinkster.co.uk/blog/2007/11/28/itunes-sharing/
     
    Toby A Inkster, Dec 14, 2007
    #16
  17. Toby A Inkster wrote:
    > Harlan Messinger wrote:
    >> Toby A Inkster wrote:
    >>> TheUsenetReader wrote:
    >>>
    >>>> in what case would the host name (the host from which the file should
    >>>> be accessed from) be anything else but localhost?
    >>> "file://foobar.example.com/c:/autoexec.bat" means "the file
    >>> 'c:/autoexec.bat' on the computer 'foobar.example.com'".

    >> It might look like it means that (depending on what "means" means) but
    >> it won't have that effect. On the Microsoft OSes the only way to access
    >> files on other computers is through shares. If the root of the C drive
    >> on foobar is shared as C$ then the URL would be
    >>
    >> file://foobar.example.com/c$/autoexec.bat

    >
    > No, that is a completely different URL.


    I know it's a different URL. It's also the way to address a file called
    autoexec.bat located in a file share c$ defined on a machine called
    foobar.example.com.

    >
    > file://foobar.example.com/c$/autoexec.bat *DOES NOT MEAN* to access share
    > "C$" on server "foobar.example.com".


    Of course it does. What else would it mean?

    >
    > The correct way to reference "C:\AUTOEXEC.BAT" on foobar.example.com is:
    >
    > file://foobar.example.com/c:/autoexec.bat


    Since the operating system doesn't *recognize* references to remote
    drives using the drive-letter-plus-colon convention, how can this be the
    correct way to reference the file? Why do you say that a way meaningless
    to the system intended to use it is the "correct way" while the way
    provided by the system for the access you intend is incorrect?

    "The file URL scheme is unusual in that it does not specify an Internet
    protocol or access method for such files; as such, its utility in
    network protocols between hosts is limited." --RFC 1738, section 3.10.
    In other words, the addressing system is whatever it is on the local
    network based on the local network's protocols. The only twist on this
    is the uniform use of forward slashes to separate the path segments, as
    this section notes:

    ... and <path> is a hierarchical directory path
    of the form <directory>/<directory>/.../<name>.

    For example, a VMS file

    DISK$USER:[MY.NOTES]NOTE123456.TXT

    might become

    <URL:file://vms.host.edu/disk$user/my/notes/note12345.txt>"
     
    Harlan Messinger, Dec 14, 2007
    #17
  18. Toby A Inkster wrote:
    > Harlan Messinger wrote:
    >
    >> If the root of the C drive on foobar is shared as C$ then the URL would
    >> be
    >>
    >> file://foobar.example.com/c$/autoexec.bat

    >
    > Further to my other post... no it is not. The way to reference the file
    > "autoexec.bat" shared using the Windows share "\\foobar.example.com\c$"
    > would be any one of these:
    >
    > file://localhost/\\foobar.example.com\c$\autoexec.bat
    > file://localhost///foobar.example.com/c$/autoexec.bat
    > file:///\\foobar.example.com\c$\autoexec.bat
    > file://///foobar.example.com/c$/autoexec.bat
    >
    > Depending on whether you want to leave out the default "localhost" part,
    > and on which types of slashes you wish to use for the Windows path.
    >

    I've never seen anyone claim that an absolute reference to another host
    is to be stated as though it were *relative* to the local machine. Where
    did you get this from?
     
    Harlan Messinger, Dec 14, 2007
    #18
  19. Harlan Messinger wrote:
    > Toby A Inkster wrote:
    >> Harlan Messinger wrote:
    >>
    >>> If the root of the C drive on foobar is shared as C$ then the URL would
    >>> be
    >>>
    >>> file://foobar.example.com/c$/autoexec.bat

    >>
    >> Further to my other post... no it is not. The way to reference the
    >> file "autoexec.bat" shared using the Windows share
    >> "\\foobar.example.com\c$" would be any one of these:
    >>
    >> file://localhost/\\foobar.example.com\c$\autoexec.bat
    >> file://localhost///foobar.example.com/c$/autoexec.bat
    >> file:///\\foobar.example.com\c$\autoexec.bat
    >> file://///foobar.example.com/c$/autoexec.bat
    >>
    >> Depending on whether you want to leave out the default "localhost"
    >> part, and on which types of slashes you wish to use for the Windows path.
    >>

    > I've never seen anyone claim that an absolute reference to another host
    > is to be stated as though it were *relative* to the local machine. Where
    > did you get this from?


    Curious, I tested these out and found that they do work in both IE6 and
    Firefox 2--except that Firefox then goes and changes all the backslashes
    to forward slashes in the Address field. My approach works in IE. It
    doesn't in Firefox, but I don't see why.
     
    Harlan Messinger, Dec 14, 2007
    #19
  20. Harlan Messinger wrote:

    > Curious, I tested these out and found that they do work in both IE6 and
    > Firefox 2--except that Firefox then goes and changes all the backslashes
    > to forward slashes in the Address field. My approach works in IE. It
    > doesn't in Firefox, but I don't see why.


    Because as I have repeatedly said, "localhost" is the only useful value
    for the "host" part of "file://" URLs.

    Putting a host in (either domain name or IP address) does *not* mean that
    the client must attempt to fetch the file from that host via some sort of
    network protocol -- it means that the user may access the file from that
    host. So "file://HOST/SOMEFILE" is not an instruction to the client to
    download SOMEFILE from HOST, but is an instruction to the user to access
    SOMEFILE from HOST -- this might require a physical walk over to HOST to
    access the file.

    If a browser resolves "file://HOST/SOMEFILE" by using CIFS (i.e. the
    protocol by which Windows machines share files and printers) to retrieve
    the file automatically, then that is a proprietary extension to the file
    protocol -- and this seems to be what IE is doing. Hardly surprising.

    > I've never seen anyone claim that an absolute reference to another host
    > is to be stated as though it were *relative* to the local machine.


    File URLs *can* be stated relative to another machine -- that's why the
    facility to specify a host exists. However, doing so is useless, because
    the file protocol specifies no mechanism which can be used to retrieve the
    file from another machine -- you just need to walk over there and access
    it.

    For example:

    file://ophelia.g5n.co.uk/vol/music/pulp_-_common_people.ogg

    refers to a particular file on my computer. However, that is useless to
    anyone who isn't logged into my computer. As I have SAMBA installed, if
    you were on my LAN however, you could access the same file at:

    \\ophelia\juke\pulp_-_common_people.ogg

    Knowing that UNC path, the file protocol URL must consist of:

    file://localhost/\\ophelia\juke\pulp_-_common_people.ogg
    file:///\\ophelia\juke\pulp_-_common_people.ogg

    (I like to use backslashes in the UNC path because it makes it clearer as
    to which slashes are part of the path and which are part of the file://
    protocol prefix to it.)

    But without knowing the UNC path, there's no way you could access that
    file from your computer. So it only makes practical sense to use file://
    URLs which are relevant to your local machine.

    --
    Toby A Inkster BSc (Hons) ARCS
    [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
    [OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 7 days, 4:10.]

    Sharing Music with Apple iTunes
    http://tobyinkster.co.uk/blog/2007/11/28/itunes-sharing/
     
    Toby A Inkster, Dec 14, 2007
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Richter

    <txt src= ...> equivalent of <img src= ...>

    Steve Richter, Feb 8, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    2,109
    Laurent Bugnion
    Feb 9, 2006
  2. Greg Johnson
    Replies:
    4
    Views:
    3,090
  3. shruds
    Replies:
    1
    Views:
    840
    John C. Bollinger
    Jan 27, 2006
  4. Replies:
    1
    Views:
    1,629
    Alex Hunsley
    Mar 23, 2007
  5. pheadxdll
    Replies:
    16
    Views:
    3,700
    Neredbojias
    Jun 6, 2007
Loading...

Share This Page