I set up my computer as a local testing server (OSX with apache and PHP) and via Dreamweaver I can now test my sites locally.
I am encountering one problem though:
I used
$_SERVER['DOCUMENT_ROOT']
a lot, as a convenient way to get my paths right.
for example, I would use
include($_SERVER['DOCUMENT_ROOT'].'/includes/top.php');
The problem is, when I test locally, I get the error message:
Warning: main() [function.include]: Failed opening '/Library/WebServer/Documents/includes/top.php' for inclusion (include_path='.:/usr/local/php5/lib/php') in /Users/seb/Sites/blablabla...
Why is there an error, and can I remedy this, without having to change my use of $_SERVER['DOCUMENT_ROOT'] in all my sites?
Is "/Library/WebServer/Documents/includes/" the right directory you want? When I use $_SERVER['DOCUMENT_ROOT'] I have to add a subfolder, even though the php file calling that variable is inside it.
Try defining a VirtualHost section for the test site with the DocumentRoot properly defined. This all depends on how you've configured apache. Maybe you're getting to the actual file being served through an Alias?
By the way this isn't very helpful:
/Users/seb/Sites/blablabla...
It's kind of important here.
Atealtha, and HardCoded,
no, 'Library/WebServer/Documents/includes/' is not the directory I want (I have no idea where that path comes from). The directory I want is:/Users/seb/Sites/blablabla...
(where blablabla is the name of the folder that contains that specific sites. I put all my sites in 'Sites').
Actually, when I think of it, the error message I get shows exactly the problem by itself:
on one hand, it says:
Failed opening '/Library/WebServer/Documents/includes/top.php'
on the other hand, it says:
for inclusion in /Users/seb/Sites/blablabla...
so when the error message wants to tell me the path that results from calling $_SERVER['DOCUMENT_ROOT'] it returns '/Library/WebServer/Documents/includes/top.php', which is WRONG
but when it tells me the path to the page I call the include function from, it returns
'/Users/seb/Sites/blablabla...' which is RIGHT
Obviously, '/Library/WebServer/Documents/includes/top.php' SHOULD be '/Users/seb/Sites/blablabla/includes/top.php'
because
/Users/seb/Sites/blablabla/ IS the document root.
And it KNOWS it, since it gives me the right path to my page accroding to its root:
'Users/seb/Sites/blablabla'
Could it be possible when you test through Dreamweaver, that "/Library/WebServer/Documents/includes/" is the temporary directory it stores the file on?
Also, echo $_SERVER['DOCUMENT_ROOT']; and see what you get.
Bookmarks