Symbolic Link

Discussion in 'Python' started by mosscliffe, Aug 18, 2007.

  1. mosscliffe

    mosscliffe Guest

    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
     
    mosscliffe, Aug 18, 2007
    #1
    1. Advertising

  2. mosscliffe schrieb:
    > 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
     
    Diez B. Roggisch, Aug 18, 2007
    #2
    1. Advertising

  3. mosscliffe

    mosscliffe Guest

    On 18 Aug, 23:49, "Diez B. Roggisch" <> wrote:
    > mosscliffe schrieb:
    >
    >
    >
    > > 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


    It is Apache.

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

    Thanks

    Richard
     
    mosscliffe, Aug 19, 2007
    #3
  4. mosscliffe schrieb:
    > On 18 Aug, 23:49, "Diez B. Roggisch" <> wrote:
    >> mosscliffe schrieb:
    >>
    >>
    >>
    >>> 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

    >
    > 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
     
    Diez B. Roggisch, Aug 19, 2007
    #4
  5. mosscliffe

    samwyse Guest

    mosscliffe wrote:
    > 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.
     
    samwyse, Aug 19, 2007
    #5
  6. mosscliffe

    mosscliffe Guest

    On 19 Aug, 13:16, samwyse <> wrote:
    > mosscliffewrote:
    > > 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.


    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
     
    mosscliffe, Aug 19, 2007
    #6
  7. mosscliffe

    Hyuga Guest

    On Aug 19, 4:29 pm, mosscliffe <> wrote:
    > 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
     
    Hyuga, Aug 20, 2007
    #7
  8. mosscliffe

    Ian Clark Guest

    Hyuga wrote:
    > On Aug 19, 4:29 pm, mosscliffe <> wrote:
    >> 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
    >


    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
     
    Ian Clark, Aug 22, 2007
    #8
  9. mosscliffe

    mosscliffe Guest

    On 22 Aug, 00:05, Ian Clark <> wrote:
    > Hyuga wrote:
    > > On Aug 19, 4:29 pm,mosscliffe<> wrote:
    > >> 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

    >
    > 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
     
    mosscliffe, Aug 23, 2007
    #9
  10. In message <>, Ian Clark
    wrote:

    > 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.
     
    Lawrence D'Oliveiro, Aug 31, 2007
    #10
  11. mosscliffe

    samwyse Guest

    mosscliffe wrote:
    > On 22 Aug, 00:05, Ian Clark <> wrote:
    >>
    >>>On Aug 19, 4:29 pm,mosscliffe<> wrote:
    >>>
    >>>>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.

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

    >
    > 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.
     
    samwyse, Sep 10, 2007
    #11
  12. In message <1o1Fi.33230$>, samwyse wrote:

    > 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.
     
    Lawrence D'Oliveiro, Sep 10, 2007
    #12
  13. mosscliffe

    samwyse Guest

    On Sep 9, 10:05 pm, Lawrence D'Oliveiro <l...@geek-
    central.gen.new_zealand> wrote:
    > In message <1o1Fi.33230$>,samwysewrote:
    >
    > > 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.


    There are reasons to use hard links, there are reasons to use symbolic
    links. Depending on the circumstances, either could "cause confusion"
    simply because either could do something other than what's needed.
    Here's a handy chart to help decide which is appropriate:
    http://publib.boulder.ibm.com/iseries/v5r1/ic2924/index.htm?info/ifs/rzaaxmstlinkcmp.htm
     
    samwyse, Oct 10, 2007
    #13
    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. Matthew Macchia
    Replies:
    3
    Views:
    1,069
    Roedy Green
    Apr 13, 2004
  2. TK

    Symbolic link

    TK, Oct 9, 2006, in forum: C++
    Replies:
    3
    Views:
    393
    Gavin Deane
    Oct 9, 2006
  3. Replies:
    6
    Views:
    11,127
    Philipp
    Apr 11, 2007
  4. Five By Five
    Replies:
    15
    Views:
    1,283
    William Gill
    Jan 14, 2009
  5. Peng Yu
    Replies:
    1
    Views:
    889
    Steven D'Aprano
    Oct 29, 2009
Loading...

Share This Page