Newbie trying to get relative paths to work.
Posted: 08. August 2006 22:19
I've worked with with PHP a little in the past, but I installed XAMPP to start learning. I'm creating a test site on my localhost first and uploading to a hosted server to implement. I just can't get relative paths to work on one or the other. I think I know the issue, but I'm wondering if there is a way to fix it.
For example, I have a site at http://localhost/site. I kept all the default settings for XAMPP so htdocs is the root folder. Under the site folder, I create the subfolders and files for the website. However, when I try to use relative paths, it goes back up to htdocs instead of site. DOCUMENT_ROOT is set to htdocs in the PHP info and I would like to keep it that way. Is it possible to to set site as the DOCUMENT_ROOT for the folders just under it only so when I upload to a hosted server I can keep all my relative path code?
Here is a specific example:
Under the site folder, I have index.php with this code:
However, htdocs is set as DR I get this error:
I know this works when uploaded, but I'd like for it to work on the localhost so I can see the final product before publishing it.
Thanks for the help.
For example, I have a site at http://localhost/site. I kept all the default settings for XAMPP so htdocs is the root folder. Under the site folder, I create the subfolders and files for the website. However, when I try to use relative paths, it goes back up to htdocs instead of site. DOCUMENT_ROOT is set to htdocs in the PHP info and I would like to keep it that way. Is it possible to to set site as the DOCUMENT_ROOT for the folders just under it only so when I upload to a hosted server I can keep all my relative path code?
Here is a specific example:
Under the site folder, I have index.php with this code:
- Code: Select all
<?php include($_SERVER['DOCUMENT_ROOT'] . "/inc/menu.php"); ?>
However, htdocs is set as DR I get this error:
Warning: include(C:/Program Files/xampp/htdocs/inc/menu.php) [function.include]: failed to open stream: No such file or directory in C:\Program Files\xampp\htdocs\site\index.php on line 48
I know this works when uploaded, but I'd like for it to work on the localhost so I can see the final product before publishing it.
Thanks for the help.