Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2002
    New York

    link to file above public_html

    Ok here is a simple question

    using php how would you display a link in the browser to a file above public_html

    So for example I have a file located at /home/username/myfile/
    which is just one up from the public_html folder

    in my php webpage I have a link like so

    PHP Code:
     $filelocation "home/username/myfile";
    "<a href='$filelocation/"
    My issue is that it them makes the link be

    So how do I fix this?

    Thanks all

  2. #2
    Join Date
    Apr 2004
    That would not work first, because you cannot access through a browser, files above the www document root. You also cannot use absolute paths as a url. They have to be relative to the public_html folder. All links are relative to your public_html folder. For example...
    to link to the file /home/whatever/public_html/index.html...

    This will not work www

    This will work www

    Although you can do it with php, it is not simple or practical and would waste resources. your best bet would be to move someplace into your public_html folder...say /home/username/public_html/movies

    the absolute path would be /home/username/public_html/movies/

    but the link would be

    and $filelocation = "www";

    Hope this helps

  3. #3
    Join Date
    Apr 2000
    You will have to have the script open and serve up the file (via the script) if you want to serve a file from outside the web root. You could also create a symbolic link (you probably don't want that, because then you may as well just have it be in the web root). So, you can create a symbolic link on the fly and have it removed after so long or after the file is downloaded. That way you save resources by not having the script serve up the file itself and the link can be temporary or even made to be accessible by a valid (timed) session or by authenticated IP (or both).

    Likely, the best option is to have something like a session based or basic auth protected file or directory that the file is in, and a valid access is done by supplying the correct credentials, and if so, it will add their IP or user/pass combination to a salted password file to allow them to then use basic auth (you can still limit per IP on top of that so they can't share the login for the site (though they can still save the file to share amongst themselves, but it'll at least save you that much more bandwidth)). It's difficult to suggest without knowing how/why you want it to work.

  4. #4
    Join Date
    Aug 2006
    I can't tell you how it works but I will tell you it can be done.

    I use an automatic download delivery script that provides an expiring download link to files that are located above the public_html directory.

  5. #5
    Join Date
    Mar 2008
    Sheffield, UK
    The script probably would have to open the file for reading (the one that's inaccessible directly), and then write to STDOUT (simulating being a server). This is a pretty complex task, as you have to make sure that the pipe is alive (otherwise you're going to gobble up resources like mad).
    If we do not plant knowledge when young, it will give us no shade when we are old.
    Lord Chesterfield

  6. #6
    Join Date
    Apr 2000
    Well, that's one way, but see my suggestions above to combat that (as it's not the only method).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts