0

I'm trying to get my <img> source to point at a file in another directory, but I'm struggling.

Currently it is:

<img src="../home/image.jpg">

When my apache2 server is in:

/var/www/html/mypage.html

I thought .. should get me there, but it doesn't work :(

Running apache2 webserver on Linux.

Edit: I also tried ../../../home/user/image.jpg, as I believe this should take me back 3 directories?

SE_1991
  • 655
  • 1
  • 7
  • 10

3 Answers3

0

Using above as your image source path would suggest that its physical path is in "/var/www/home/image.jpg". Is this correct? I would also assume that your apache's root directory is at /var/www/html. You can try hard-coding the actual and complete physical path of your image for tracing purposes, but it's not going to a good practice. Finally, you can trace it in your apache logs as to what actual location is being accessed in your given img source path.

Lane
  • 366
  • 1
  • 2
  • 11
  • No, the path is /home/user, whereas the html is in /var/www/html – SE_1991 Feb 28 '16 at 18:00
  • So the complete actual path of the image is at /home/user/image.jpg? You can use "../../../home/user/image.jpg", but it's shorter to hard-code the actual path instead. Alternately, I would suggest to create a symbolic link at your /var/www/html that works like a shortcut to your /home/user directory. For example, in your var/www/html directory, create a symbolic folder named images pointing to /home/user. With your image source now, you can simply access it using – Lane Feb 28 '16 at 18:04
0

Any path which start with "/" is relative to root for more details click here. if your image is in "home" directory and "www" is your root directory then you can use

"/home/image.jpg"

If your image is in a directory which is not in root directory of server you can't access it from outside. I think you have placed image in wrong directory your image must should be with in apache root directory. If a client can access all files from server then your server is naked to hackers they can steel any kind of information they want!

Community
  • 1
  • 1
Rehan Haider
  • 893
  • 11
  • 26
0

I used mount to get one folder appear in the web server folder tree. Not sure, but I think mounting file is also possible.

sudo mount -o bind /sourcefolderurl /destinationfolderurl

Web server to traverse all the folders up to root and then to another folder would be really bad idea. Some web servers create limited permissions user that can't escape the www folder.

Gergo
  • 93
  • 1
  • 7
  • This does NOT work. Just got rid of my entire html dir and replaced it with the other one! – SE_1991 Feb 28 '16 at 18:27
  • I mean - mount /home/userX/SomeSubDir as /var/www/html/RemountedSubDir. As far as I remember symlink did not work for me and you also have to change/check the permissions (if not changed already) to free for everyone to read or check the "server user" permissions. I think mounting sub dir in sub dir is best, because if not persistent, you can loose lot of functionality after reboot. – Gergo Feb 28 '16 at 21:02