views:

70

answers:

5

Hello, Can anybody tell me how do i give absolute path of the img tag's src attribute?

The following doesn't work

 <img alt="NO IMAGE" src="/home/administrator/tiger-info0[1].gif"/>

I am working On Ubuntu and i am very sure that image exists on this path.

A: 

hmm why don't you copy the image to your web directory and give it the relative path? you server (apache?) may not be able to access the file to serve the browser.

phunehehe
It's little complex to explain but basically i work in java and allow my users to upload files and if i give relative path, it works but as soon as i clean and build my application, Java application server deletes the folder from build/web/Images. Can you tell me how can i give absolute path to img?
Ankit Rathod
A: 

if you are making a local html page you can use that path but if you are creating a website you have to use the absolute path to the document root. And make sure the image path is correct (use firebug)

Galen
+2  A: 

This is probably happening because the image is located outside the web server's document root.

Your web server will not be able to serve anything from outside the document root. One possible workaround is to use a scripting language that has access to the file system, and route the images through the script. For example, you may want to check out the following implementation in php:


You can also create a symbolic link of /home/administrator/ into the document root:

ln -s /www/yoursite /home/administrator
Daniel Vassallo
Yes, it is outside my document root but i need it that way only. If i give relative path Java application server simply deletes my folder when i clean and rebuild my project. It's a very small issue but needless to say i am trying since many hours to resolve it. Don't know why does it delete my folders. It considers them as temporary
Ankit Rathod
+1 for the symbolic link
phunehehe
A: 

Give your path correctly with domain or use ../ or ./ is for to represent correct relative path.

Karthik
A: 

You cannot access files that are not in your document root. Get Java application server to not delete your folder. You can probably do this by having one folder into which your users can upload files, and add that folder to your project. You can let users create subfolders inside that main folder, and since the main folder is a part of your project, cleaning the build will not automatically delete it or its subfolders.

Amey