473,466 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Absolute or relative paths

Hi all,

I am having trouble using with using paths on my website. Is there a
way to use an absolute path that always refers to the website's root
directory...or do I need to use a relative path?

The problem I am having is how to refer to my "/images" directory no
matter where it is referenced in the website's directory structure.

I have used the URI (http://www.mysite.com/images), but that seems too
complex, especially if I needed to reference other directories. I know
that PHP must have a simpler solution.
Thank you in advance,

Miki
Jul 17 '05 #1
3 1829
michelle wrote:
Hi all,

I am having trouble using with using paths on my website. Is there a
way to use an absolute path that always refers to the website's root
directory...or do I need to use a relative path?

The problem I am having is how to refer to my "/images" directory no
matter where it is referenced in the website's directory structure.

I have used the URI (http://www.mysite.com/images), but that seems too
complex, especially if I needed to reference other directories. I know
that PHP must have a simpler solution.
Thank you in advance,

Miki

Check out $_SERVER['DOCUMENT_ROOT']
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 17 '05 #2
michelle wrote:
Is there a way to use an absolute path that always refers to the
website's root directory...or do I need to use a relative path?
Aye.
The problem I am having is how to refer to my "/images" directory no
matter where it is referenced in the website's directory structure.
Probably /images/ (note the trailing slash).
I have used the URI (http://www.mysite.com/images), but that seems too
complex,
I'd imagine it has other side effects too.
I know that PHP must have a simpler solution.


To refer to the URI

http://domain.invalid/images/

with a base URI of

http://domain.invalid/foo/

either <../images/> or </images/>; the latter works regardless
of base URI.

--
Jock
Jul 17 '05 #3
Within plain HTML if you start a URL with "/" that refers to the root
level of the domain and your absolute URL will be good. For example,

<img src="/images/myFile.gif" />

should work no matter where it's used.

However everything's different within PHP code. If want to refer to an
absolute path inside of <? and ?> then you need to use a different
strategy. One thing that works is to precede your absolute path with
"$_SERVER['DOCUMENT_ROOT'] like this:

<? include($_SERVER['DOCUMENT_ROOT'] . '/include/navbar.inc'); ?>

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Stuart | last post by:
Hi All, I got a challenge to make the same APS/Script/Html run on different web roots. I can not use relative pathing in a lot of cases. We use lots of included files so depending on where that...
15
by: Nick K. | last post by:
I recently began maintenance work on a production web server that is located in the root directory of a web server. I moved this into a sub web on my local web server in order to do work on it. I...
6
by: David Siroky | last post by:
Hi! When I "compile" my python files with "python -OO ...." into pyo files then they still contain absolute paths of the source files which is undesirable for me. How can I deal with that? ...
4
by: Vitali Gontsharuk | last post by:
Hallo! When using the XPATH document() function to load a new XML document, we are coming across problems, because XALAN seems to have problems with absolute paths. XALAN always assumes that the...
7
by: Rizaan Jappie | last post by:
is it possible to get the relative path based on a absolute path in c#? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
0
by: Jason Lawrence | last post by:
I have an attributed ATL project (call it B) that I am building with Microsoft Visual C++ .NET (55537-640-3684941- 18356). In the project I include the COM generated file A.h (from another ATL...
2
by: David Cho | last post by:
This is a simple issue I am trying to figure out. How would I express absolute paths to various aspx files in the aspx page. I am not intereted in relative paths. For example, I want to...
0
by: Chris Gill | last post by:
I'm trying to use cookieless sessions in asp.net using the InProc mode (for various reasons it is not desirable for us to use the other modes if it is possible to avoid them). My problem revolves...
19
by: Jerry M. Gartner | last post by:
Greetings: What is the best way to resolve paths within a document regardless of what path it is opened under? For example: I have x.php and it contains <img src="images...">, (amongst other...
6
by: Jon Slaughter | last post by:
do I have to prefix every absolute path with document root to get it to work? For some reason I thought that prefixing a path with '/' or './' with make it absolute w.r.t to document root but I...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.