Symbolic Link

M

mosscliffe

I am trying to create a link to a file, which I can then use in an
HTML page.

The system is Linux on a hosted web service, running python 2.3.
Other than that I have no knowledge of the system.

The link is created OK, but when I try to use it as filename for the
IMG TAG, it does not get displayed. The page source of the created
page is pointing to the link as temp/test1.jpg

Any ideas ?

srcFile = "temp/test2.jpg"

linkFile = "temp/test1.jpg"

if os.path.islink(linkFile):
print "Link Exists", nl
pass
else:
print "Making Link", nl
os.symlink(srcFile, linkFile)

print '<BR><img src="%s">the image</IMG><BR><BR>' % linkFile

print '<img src="%s">the image</IMG>' % srcFile
 
D

Diez B. Roggisch

mosscliffe said:
I am trying to create a link to a file, which I can then use in an
HTML page.

The system is Linux on a hosted web service, running python 2.3.
Other than that I have no knowledge of the system.

The link is created OK, but when I try to use it as filename for the
IMG TAG, it does not get displayed. The page source of the created
page is pointing to the link as temp/test1.jpg

Any ideas ?

srcFile = "temp/test2.jpg"

linkFile = "temp/test1.jpg"

if os.path.islink(linkFile):
print "Link Exists", nl
pass
else:
print "Making Link", nl
os.symlink(srcFile, linkFile)

print '<BR><img src="%s">the image</IMG><BR><BR>' % linkFile

print '<img src="%s">the image</IMG>' % srcFile

In what environment is that script running? If it's apache, it might be
that the apache settings disallow for following links.

Diez
 
M

mosscliffe

mosscliffe schrieb:












In what environment is that script running? If it's apache, it might be
that the apache settings disallow for following links.

Diez

It is Apache.

Can I create some override in the current directory. I am afraid my
Apache skills are almost zero.

Thanks

Richard
 
D

Diez B. Roggisch

mosscliffe said:
It is Apache.

Can I create some override in the current directory. I am afraid my
Apache skills are almost zero.

As are mine. At least from the top of my head. You better ask in a more
apache-centric forum.

Diez
 
S

samwyse

mosscliffe said:
I am trying to create a link to a file, which I can then use in an
HTML page.

The system is Linux on a hosted web service, running python 2.3.
Other than that I have no knowledge of the system.

The link is created OK, but when I try to use it as filename for the
IMG TAG, it does not get displayed. The page source of the created
page is pointing to the link as temp/test1.jpg

What are you trying to do that you can't use the original file instead
of creating a link? There might be a way to side-step the entire problem.
 
M

mosscliffe

mosscliffewrote:



What are you trying to do that you can't use the original file instead
of creating a link? There might be a way to side-step the entire problem.

The source file is in an area which python can see, but not the
browser. I am trying to make a link in a browser friendly area so I
can use it to display an image file.

Thanks

Richard
 
H

Hyuga

The source file is in an area which python can see, but not the
browser. I am trying to make a link in a browser friendly area so I
can use it to display an image file.

You might want to try using an .htaccess file. Place a file
called .htaccess in the "browser friendly area" and place in it the
line:

Options +FollowSymLinks

Assuming your hosting service will allow that, then it should work.
If not, then why not just copy the image files? Storage is cheap
these days.

Hyuga
 
I

Ian Clark

Hyuga said:
You might want to try using an .htaccess file. Place a file
called .htaccess in the "browser friendly area" and place in it the
line:

Options +FollowSymLinks

Assuming your hosting service will allow that, then it should work.
If not, then why not just copy the image files? Storage is cheap
these days.

Hyuga

My question would be why a symbolic link? Why not a hard link? Are the
two directories on different mount points? After the script finishes
does python need to see that image file again? Why not just move it?

Ian
 
M

mosscliffe

My question would be why a symbolic link? Why not a hard link? Are the
two directories on different mount points? After the script finishes
does python need to see that image file again? Why not just move it?

Ian

I just imagined a symbolic link would be quicker.

I have tested a hard link now and it seems to work fine. I am
deleting the link/s at the end of the session/s.

I think a link is better than a move, because there is always a
possibility I might somehow delete the moved file and then I would
lose the original one.

Thanks for your help.

Richard
 
L

Lawrence D'Oliveiro

Ian Clark said:
My question would be why a symbolic link? Why not a hard link?

Because of the potential for confusion. For instance, modifying the file
without realizing that some other place expects to see the unmodified
version.
 
S

samwyse

mosscliffe said:
I have tested a hard link now and it seems to work fine. I am
deleting the link/s at the end of the session/s.

This is a bit late, but the reason the symbolic link won't work is
because it's the web-server that's resolving it. The browser can only
see things that the web-server, huh, serves, so what was meant in the
first paragraph above was that the web server couldn't access the file
in its original location. If you create a sym-link, the web server
opens the link, finds out the actual location of the file, and tries to
open that file, which it still can't do. A hard-link, OTOH, allows
direct access to the contents of a file, as long as it is on the same
filesystem. No extra steps are required, so the process runs a few
microseconds faster, and directory-level permissions can't get in the way.
 
L

Lawrence D'Oliveiro

A hard-link, OTOH, allows
direct access to the contents of a file, as long as it is on the same
filesystem. No extra steps are required, so the process runs a few
microseconds faster, and directory-level permissions can't get in the way.

Hard links are best avoided, because of the confusion they can cause.
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top