This is the path of my html file ie test.html
/var/www/html/1/2/3/4/5/6/7/8/9/test.html
i want images from this path:
/var/www/html/1/2/3/4
How i able to do in img tag, src attribute.
You should take a look at Absolute and Relative Paths
in your case writing <img src="."/> is your current path so it's equivalent to /var/www/html/1/2/3/4/5/6/7/8/9/test.html (. means current directory)
now you can go some directories up using ".." so you can move up to your desired path using this method : <img src="../../../../../img.jpg">
These two methods are called Relative paths and that's what you should use in your websites since you can sometimes have to migrate your website and absolute paths wouldn't work anymore
For example if you write
<img src="http://html/1/2/3/4/img.jpg"/> it would still work but only if your site is named "html" and the directory logic stays the same
hope it helped !
Hope i understand your question.
The path should be like this
../../../../../img.jpg
each ../ will take you back to one folder .. Could you try this..
Use relative path, .. means dir up, so the path in index.html to img.jpg has to be:
<img src="../../../../../img.jpg">
Related
I cant seem to get my image to display on my webpage using a relative path. Im using the program "brackets" to do all of my editing before uploading to the webpage. Below is the relative path that i'm using and when I hover over the path the image thumbnail displays. but it still wont display on the page... am I missing anything? please and thank you.
<img id="01" class ="tn leftcol" width = "150" height = "150"
src=".//Images/IMG_3604.JPG" alt="1" />
there are two slashes. this can be interpreted as a protocol. Change the src to Images/IMG_3604.JPG
If this is being populated via a variable, check the source text or environments
There are two forward slashes. It should be ./Images/xxxxx.png not .//
If you have to go out of a directory, use ../ if the image folder is in the folder you are currently in use nothing.
Src="Images/IMG_3604.JPG"
Your html file is in the same directory.
Src="../Images/IMG_3604.JPG"
Html file is in a subdirectory and you need to go outside of that folder to get to images.
Src="../../Images/IMG_3604.JPG"
Html is in a subdirectory of a subdirectory and you need to go outside of both to get to the Images folder.
Hope this helps.
I have my images in '/src/main/webapp/images' folder and my html code is in '/src/main/webapp/app/report' folder. How to specify the path to the image mentioned in that other directory?
I have tried:
<img src=".//src/main/webapp/images/pdf-file_128.png">
and also:
<img src="/src/main/webapp/images/pdf-file_128.png">
Note I am currently in webapp/app/report directory...
Thanks in advance!
Generally, you should be able to specify a Relative Path, using /../ to traverse up each directory level:
"../../images/image01.png"
Below are the relative path rules that you should know :
"/" returns to the root directory and starts path there
"../" moves one directory back and starts path there
"../../" moves two directories backward and starts path there (and so on...)
You need to go two level up to include the image in images folder as below :
<img src="../../images/pdf-file_128.png">
From your current directory, this should be the path to your image
../../images/your image name.png
I've finished up my website and I'm trying to clean up the files. I've put all my images in a folder called images and I'm trying to set up the path directory from the root folder but to no avail. As far as I can tell I'm doing nothing wrong?
<img src="images/logo.png">
The root folder contains the html file with logo inside it and another folder called images with logo.png inside it.
Would anybody know what the problem is?
All help really appreciated!
The path is right but if you are using a url rewrite like engine htaccess the paths may be problematic, then you can set an absolute path instead of a relative:
<img src="/images/logo.png">
The issue looks like relative paths, so instead of:
<img src="images/logo.png">
try
<img src="/images/logo.png">
In the suggested approach notice the leading forward slash /
You may find the following useful: http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/
If I set a filepath for an image like src="images/anotherFolder/picture.jpg" on the start page of my website it works great. But if I then visit www.mywebsite.com/albums and use the same src, it doesn't work at all. And if check the image path given in Chrome I see that it's looking for an image with an URL which looks like this:
www.mywebsite.com/albums/images/anotherFolder/picture.jpg
instead of this:
www.mywebsite.com/images/anotherFolder/picture.jpg
So I thought that I would use a source that looked like this instead:
src="http://www.mywebsite.com/images/anotherFolder/edit.jpg" which works on both pages BUT then PHP functions such as is_file, is_readable, file_exists wont work properly.
So, what to do?
ADDED
I use a .htaccess file to rewrite the URL from http://www.mywebsite.com/albums?id=123 to http://www.mywebsite.com/albums/123
What you want is called relative paths.
If you want a relative path to the root of your site, you should start with a slash: /
src="/images/anotherFolder/picture.jpg"
And if you want relative path to the parent folder, you should start with two dots and a slash: ../
So if you are in www.mywebsite.com/albums,
src="../images/anotherFolder/picture.jpg"
and if you are in www.mywebsite.com/albums/aaa,
src="../../images/anotherFolder/picture.jpg"
Edit:
It seems that is_file doesn't work with relative paths from root, but it works with ../.
If you prefer relative paths from root, you can use
$_SERVER['DOCUMENT_ROOT']."/images/anotherFolder/picture.jpg"
Use src="./images/anotherFolder/edit.jpg"
I am working on a code where all the images are referred with a preceding "/"
eg:
<img alt="" class="repositioned" src="/images/top-b-strip.jpg" />
I have a wamp server where I run the code and find that image is not coming correctly until I remove the prceeding "/" before images.
<img alt="" class="repositioned" src="images/top-b-strip.jpg" />
Can anybody explain anything I am missing here?
Putting a "/" at the start of your path denotes that it's absolutely situated at the root of your server. For instance, http://www.example.com/images/top-b-strip.jpg, where as you may actually have them as http://www.example.com/somesubaccount/images/top-b-strip.jpg.
You can read more about absolute versus relative paths at, for instance, http://www.communitymx.com/content/article.cfm?cid=230ad
/images/top-b-strip.jpg is an absolute path, where you need to use a relative path (without the first /).
This means that images is actually a subdirectory of the directory where your html file is, while if you use the absolute path, the images folder is supposed to be a subfolder of the root directory of the file system.