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

T

TheUsenetReader

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?
 
A

Andy Dingley

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.
 
T

Toby A Inkster

TheUsenetReader said:
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/
 
B

Bergamot

Toby said:
<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">
 
T

Toby A Inkster

Bergamot said:
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:

said:
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/
 
H

Harlan Messinger

Bergamot said:
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.
 
T

TheUsenetReader

"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:



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?
 
B

Bergamot

Toby said:
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.
 
T

Toby A Inkster

TheUsenetReader said:
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/
 
H

Harlan Messinger

Toby said:
"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.
 
J

Jonathan N. Little

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">
 
T

Toby A Inkster

Harlan said:
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/
 
T

Toby A Inkster

Harlan said:
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/
 
H

Harlan Messinger

Toby said:
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>"
 
H

Harlan Messinger

Toby said:
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?
 
H

Harlan Messinger

Harlan said:
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.
 
T

Toby A Inkster

Harlan said:
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/
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top