May 18, 200818 yr I was wondering if it's possible to access files from the root folder of a website whilst in a different folder. For example, in my current website which I'm building, I want to have a 'blog' folder with sub-folders. However, I want to be able to include the 'main.css' file and the 'imgs' folder which are in the website root. Is this possible? And, if so, can I then add more sub-folders so that the website looks like this: root / blog / May / June / July etc... Sorry if I explained it badly!
May 18, 200818 yr If your folder structure was like this: root / blog / May and you had a css file called my.css in root, for May to access the css file you would use <link rel="stylesheet" type="text/css" href="../../my.css" />
May 18, 200818 yr Author If your folder structure was like this:root / blog / May and you had a css file called my.css in root, for May to access the css file you would use <link rel="stylesheet" type="text/css" href="../../my.css" /> Ah, okay. So what about accessing the 'imgs' folder? Would this work: <img src="../../imgs/image-example.jpg">
May 18, 200818 yr Ah, okay. So what about accessing the 'imgs' folder? Would this work: <img src="../../imgs/image-example.jpg"> Yes. As long as that is the correct relative path from the document.
May 18, 200818 yr Author Yes. As long as that is the correct relative path from the document. Awesome, thanks for the help!
May 19, 200818 yr If you have your headers in an include.php and you don't wanna create diffrent includes for every folder level you can also just use the entire url. <img src="http://www.yourdomain.com/images/yourimage.jpg"> This way it doesn't matter if you move pages or create another subdirectory.
May 19, 200818 yr Or you could just use <img src="/imgs/image-example.jpg"> or <link rel="stylesheet" type="text/css" href="/my.css" /> and never need to worry about../../../ again
Create an account or sign in to comment