#1
  1. PHP user-in-training
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2001
    Location
    Sacramento Calif. USA
    Posts
    677
    Rep Power
    0

    Question Why do my paths outside my web directory not work?


    I have been using php for ages, but not so long with Unix/Linux.

    I recently built and began using an Ubuntu server (11.10) and have been happy with it so far.

    But I have come across a problem that I am not sure of, and may be related to my lack of Linux knowledge.

    In Ubuntu, Apache2, the default wed directory is under /var/www.

    I am trying to reference files from one website directory to another, and cannot get it to work for some reason. So I was wondering if it is an illegal operation.

    For example I have:

    /var/www/green.com/files
    and
    /var/www/blue.com/files

    If I try to do this from the blue.com directory for example.
    <img src='/var/green.com/files/01234.jpg' />

    It will not work.

    Is it not possible to reference files outside of your primary web directory?

    BTW I asked this in the Ubuntu forums and got stupid answers like use 'www.green.com/01234.jpg', which obviously does not answer the question, and is not at all what I am going to do if I am referencing hundreds of files dynamically.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    49
    Rep Power
    0
    it dpends on the kind of access, you can execute external files through symblinks and exec() pass_thru()

    you can parse file using file_get_contents() and file()

    you cannot use a php file as a page on your site
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    49
    Rep Power
    0
    and php wont do many things when its in safe mode todo with filesystem as it passes the uid checks that is linux chmod etc
  6. #4
  7. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,549
    Rep Power
    2337
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  8. #5
  9. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    You can not use an absolute local filesystem path in HTML.

    Writing this:
    Code:
    <img src='/var/www/green.com/files/01234.jpg' />
    Is like writing this:
    Code:
    <img src='C:\www\green.com\files\01234.jpg' />
    Since the user's browser does not have local filesystem access to your server it cannot possibly look up a remote file using an absolute filesystem path.

    Using something like http://www.green.com/files/01234.jpg is actually a correct answer, because Apache will resolve www.green.com to point to the local /var/www/green.com/ directory, and then it will be able to find the file 01234.jpg and serve it to the client.

    If you want to be able to access the file through the blue.com domain, then you will have to use mod_alias or mod_rewrite, as ptr2void pointed out. You could create an alias that maps www.blue.com/green.com/files to /var/www/green.com/files/, and then you would be able to use "/green.com/files/01234.jpg" or "http://www.blue.com/green.com/files/01234.jpg" as your img src.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  10. #6
  11. PHP user-in-training
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2001
    Location
    Sacramento Calif. USA
    Posts
    677
    Rep Power
    0

    Ok I need to make this clearer I think


    /var/www/green.com/sub/display.php
    /var/www/green.com/code/images/

    If I want the php script "display.php" to reference items in the images directory I believe I should be able to use

    PHP Code:
    src='../../code/images/".$member['photo']."' 
    the "../../" says to step up two directories, which would put me at "/var/www/green.com/".
    Then add on "code/images/"
    which should put me at "/var/www/green.com/code/images/".

    where my php script would display a file $member['photo'], if it found it in the directory.

    Now is this wrong? Why does this not work?
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    49
    Rep Power
    0
    you have to make a alias for each remote folder, for just a base directory folder
  14. #8
  15. PHP user-in-training
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2001
    Location
    Sacramento Calif. USA
    Posts
    677
    Rep Power
    0
    Originally Posted by p0rt
    you have to make a alias for each remote folder, for just a base directory folder
    Can you expand on that with maybe an example?
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    49
    Rep Power
    0
    a folder is a single folder :

    /var/www/green.com/code/images/

    a directory would be :

    /var/www/green.com/

    so you can still goto /var/www/green.com/code/images/ and use ../ to go up a level to /var/www/green.com/code/
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Sep 2006
    Posts
    2,011
    Rep Power
    534
    Code:
    <img src='/var/green.com/files/01234.jpg' />
    Your client cannot access anything in var. It only can access var/www (or var/http depending on how your server is set up). Try just the following:
    Code:
    <img src='green.com/files/01234.jpg' />
    also, within PHP, I recommend using full names as it prevents silly mistakes.
  20. #11
  21. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    Now is this wrong? Why does this not work?
    It doesn't work because you're still constructing your paths using filesystem paths.

    If the URL http://green.com/sub/display.php contains src='../../code/images/file12345.html' the browser will choke because you're telling it to load "http://green.com/sub/../../code/images/file12345.html". Your web path is /sub; you can't go up two directory levels at this point because your web path is only one directory level long.

    /var/www/green.com/sub/display.php
    the "../../" says to step up two directories, which would put me at "/var/www/green.com/".
    "../../" would actually step you into "/var/www". Your web path cannot step above "/var/www/green.com/".


    Using mod_alias you could construct an alias under green.com that points to files in the blue.com domain. For example:
    Code:
    Alias /blue_images /var/www/blue.com/images
    This means that if you put "http://www.green.com/blue_images/sub/123.gif" or "/blue_images/sub/123.gif" in your src attribute, the server will return the file /var/www/blue.com/images/sub/123.gif from the filesystem.

    Although in many circumstances there is pretty much no advantage to doing that vs just writing http://www.blue.com/images/sub/123.gif in your src attribute.


    There is no way to configure your server that will allow you to use filesystem URLs in HTML.
    Last edited by E-Oreo; March 19th, 2012 at 07:00 PM.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo