Pathways & References
Moderator: General Moderators
Pathways & References
Hello! I hope Tuesday is treating everybody right.
I thought this post was more of a "theory and design" issue than a code one, but forgive me if I'm wrong. I'm also aware this is not a new issue, and has been discussed on an endless number of forums and sites. As a php brand newbie, none of the info I've seen completely light the bulb for me, so to speak. I've been redoing a rather large and as of yet unpublished web I created several years ago in straight html and have crash landed into the world of php. Though I intend to take a thorough approach to learning all the ins and outs, I need to have this website (with its 140+ pages) ready to go within a few days....and I've already lost a few on trial and error.
On my computer, I am working with an Apache server which is set up as C://server/Apache/www/myserver.dev/public_html. As per the Apache httpd, the document root is htdocs (C://server/Apache/). All the files I'm designing within this server will need to be uploaded to another server once completed. "AddType application/x-httpd-php .html" is set up both *within the Apache httpd config* and *within a separate .htaccess file* file (the latter for the purposes of uploading to the other server).
Within public_html are my index.html and style.css files, as well as the following folders:
includes (which has header.php, footer.php, get_meta.php, introline.php, and sidebar.php)
counties (120 .html files, all of which use each of the above noted includes)
interests (10+ .html files, all of which use each of the above noted includes)
images (5+ image files)
The header, footer, and sidebar php files reference files in the images folder.
When all the .html and .php files are together in one folder, everything works fine. However, once separated into folders, I'm lost. I've tried various different manners of reference, including the format of
<?php include $_SERVER['document_root'] ."/includes/header.php"; ?>
But no luck. Each include returns these three errors:
Notice: Undefined index: document_root in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Warning: include(/includes/header.php) [function.include]: failed to open stream: No such file or directory in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Warning: include() [function.include]: Failed opening '/includes/header.php' for inclusion (include_path='.;C:\php5\pear') in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
I also tried moving my includes folder up to the same level as the public_html folder.
Can someone please babystep me through this? What do I need to do to make sure (1) my html's can properly and "dynamically" refer to includes in other directories, (2) my includes can refer to images in other directories, and (3) that all this will still work when I upload to another server.
Thanks so much in advance,
Brittanie
I thought this post was more of a "theory and design" issue than a code one, but forgive me if I'm wrong. I'm also aware this is not a new issue, and has been discussed on an endless number of forums and sites. As a php brand newbie, none of the info I've seen completely light the bulb for me, so to speak. I've been redoing a rather large and as of yet unpublished web I created several years ago in straight html and have crash landed into the world of php. Though I intend to take a thorough approach to learning all the ins and outs, I need to have this website (with its 140+ pages) ready to go within a few days....and I've already lost a few on trial and error.
On my computer, I am working with an Apache server which is set up as C://server/Apache/www/myserver.dev/public_html. As per the Apache httpd, the document root is htdocs (C://server/Apache/). All the files I'm designing within this server will need to be uploaded to another server once completed. "AddType application/x-httpd-php .html" is set up both *within the Apache httpd config* and *within a separate .htaccess file* file (the latter for the purposes of uploading to the other server).
Within public_html are my index.html and style.css files, as well as the following folders:
includes (which has header.php, footer.php, get_meta.php, introline.php, and sidebar.php)
counties (120 .html files, all of which use each of the above noted includes)
interests (10+ .html files, all of which use each of the above noted includes)
images (5+ image files)
The header, footer, and sidebar php files reference files in the images folder.
When all the .html and .php files are together in one folder, everything works fine. However, once separated into folders, I'm lost. I've tried various different manners of reference, including the format of
<?php include $_SERVER['document_root'] ."/includes/header.php"; ?>
But no luck. Each include returns these three errors:
Notice: Undefined index: document_root in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Warning: include(/includes/header.php) [function.include]: failed to open stream: No such file or directory in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Warning: include() [function.include]: Failed opening '/includes/header.php' for inclusion (include_path='.;C:\php5\pear') in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
I also tried moving my includes folder up to the same level as the public_html folder.
Can someone please babystep me through this? What do I need to do to make sure (1) my html's can properly and "dynamically" refer to includes in other directories, (2) my includes can refer to images in other directories, and (3) that all this will still work when I upload to another server.
Thanks so much in advance,
Brittanie
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Pathways & References
What is the fullpath to your /includes directory?
Also, $_SERVER['document_root'] is not the same as $_SERVER['DOCUMENT_ROOT'].
Also, $_SERVER['document_root'] is not the same as $_SERVER['DOCUMENT_ROOT'].
Re: Pathways & References
Thanks for your reply!
As of this moment, the full path is c://server/Apache/www/myserver.dev/includes. Note this is a little different than when I posted a little while ago, as then it was c://server/Apache/www/myserver.dev/public_html/includes - I'm still playing around with everything. I've also added
php_value include_path ".:/home/myserver.dev/includes
to my .htaccess file.
I was not aware document_root and DOCUMENT_ROOT were not the same thing, however I have tried DOCUMENT_ROOT still without luck.
As of this moment, the full path is c://server/Apache/www/myserver.dev/includes. Note this is a little different than when I posted a little while ago, as then it was c://server/Apache/www/myserver.dev/public_html/includes - I'm still playing around with everything. I've also added
php_value include_path ".:/home/myserver.dev/includes
to my .htaccess file.
I was not aware document_root and DOCUMENT_ROOT were not the same thing, however I have tried DOCUMENT_ROOT still without luck.
Re: Pathways & References
What do I need to do to make sure (1) my html's can properly and "dynamically" refer to includes in other directories
Code: Select all
include dirname(__FILE__) . '/includes/header.php';
, (2) my includes can refer to images in other directories,
Code: Select all
<img href="images/something.png" alt="something"/>
Re: Pathways & References
Thank you, Weirdan, but that does not work either. With the includes folder either in the main directory or above it, nor either with or without the include_path statement in the .htaccess file.
Re: Pathways & References
With the statement: php_value include_path ".:/home/myserver.dev/public_html/includes in my .htaccess file (note I've also tried alternating "home" with "www" ---- my full path is c://server/Apache/www/myserver.dev/ ) and the includes folder in the same directory as the public_html folder (myserver.dev) I get the following:
Notice: Use of undefined constant _FILE_ - assumed '_FILE_' in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Warning: include(.includes/header.php) [function.include]: failed to open stream: No such file or directory in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Warning: include() [function.include]: Failed opening '.includes/header.php' for inclusion (include_path='.:/www/myserver.dev/includes') in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Without the statement in the htaccess file, I get:
Notice: Use of undefined constant _FILE_ - assumed '_FILE_' in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Warning: include(.includes/header.php) [function.include]: failed to open stream: No such file or directory in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Warning: include() [function.include]: Failed opening '.includes/header.php' for inclusion (include_path='.;C:\php5\pear') in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
With the includes folder inside the public_html directory (without the statement in .htaccess) I get:
Notice: Use of undefined constant _FILE_ - assumed '_FILE_' in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Warning: include(.includes/header.php) [function.include]: failed to open stream: No such file or directory in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Warning: include() [function.include]: Failed opening '.includes/header.php' for inclusion (include_path='.;C:\php5\pear') in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Keep in mind I probably need babystepping. Do not assume I know or have done/configured/etc. in anyway.
Notice: Use of undefined constant _FILE_ - assumed '_FILE_' in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Warning: include(.includes/header.php) [function.include]: failed to open stream: No such file or directory in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Warning: include() [function.include]: Failed opening '.includes/header.php' for inclusion (include_path='.:/www/myserver.dev/includes') in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Without the statement in the htaccess file, I get:
Notice: Use of undefined constant _FILE_ - assumed '_FILE_' in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Warning: include(.includes/header.php) [function.include]: failed to open stream: No such file or directory in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Warning: include() [function.include]: Failed opening '.includes/header.php' for inclusion (include_path='.;C:\php5\pear') in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
With the includes folder inside the public_html directory (without the statement in .htaccess) I get:
Notice: Use of undefined constant _FILE_ - assumed '_FILE_' in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Warning: include(.includes/header.php) [function.include]: failed to open stream: No such file or directory in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Warning: include() [function.include]: Failed opening '.includes/header.php' for inclusion (include_path='.;C:\php5\pear') in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Keep in mind I probably need babystepping. Do not assume I know or have done/configured/etc. in anyway.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Pathways & References
_FILE_ is not the same as __FILE__ 
Re: Pathways & References
Thank you kindly =) Didn't notice that either.
However, unfortunately, still no help.
Warning: include(C:\server\www\myserver.dev\public_html\counties../includes/header.php) [function.include]: failed to open stream: No such file or directory in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Warning: include() [function.include]: Failed opening 'C:\server\www\myserver.dev\public_html\counties../includes/header.php' for inclusion (include_path='.;C:\php5\pear') in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Same general error with and without the .htaccess statement and whether or not the includes folder is on the same directory as or within public_html.
However, unfortunately, still no help.
Warning: include(C:\server\www\myserver.dev\public_html\counties../includes/header.php) [function.include]: failed to open stream: No such file or directory in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Warning: include() [function.include]: Failed opening 'C:\server\www\myserver.dev\public_html\counties../includes/header.php' for inclusion (include_path='.;C:\php5\pear') in C:\server\www\myserver.dev\public_html\counties\bath.html on line 30
Same general error with and without the .htaccess statement and whether or not the includes folder is on the same directory as or within public_html.
Re: Pathways & References
The warning is telling you precisely what the problem is. Just modify the path until it points exactly to where the file is residing.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- flying_circus
- Forum Regular
- Posts: 732
- Joined: Wed Mar 05, 2008 10:23 pm
- Location: Sunriver, OR
Re: Pathways & References
It is important that you are conscientious of which slash to use and where. MS-DOS like operating systems use a backslash to indicate directory structure (ex. c:\windows\). Unix like operating systems use the foreward slash (ex. /usr/www/data/). HTTP URI's use the forward slash as well.
If you are outputting a path in HTML, such as in an a href or img src, you need to use forward slashes.
If you are using a filesystem path, such as in a php include, then you need to know which slash to use on whatever operating system your webserver is installed on.
PHP has a pre-defined constant called DIRECTORY_SEPERATOR, which will take the guess work out of it, and make your application more portable.
consider doing something like this:
If you are outputting a path in HTML, such as in an a href or img src, you need to use forward slashes.
If you are using a filesystem path, such as in a php include, then you need to know which slash to use on whatever operating system your webserver is installed on.
PHP has a pre-defined constant called DIRECTORY_SEPERATOR, which will take the guess work out of it, and make your application more portable.
consider doing something like this:
Code: Select all
<?php
define('DS', DIRECTORY_SEPERATOR);
$current_dir = dirname(__FILE__);
/* This will output a string like: C:\server\www\myserver.dev\public_html\counties\..\includes\ */
$includes_dir = $current_dir . DS . '..' . DS . 'includes' . DS;
include($includes_dir . 'header.php');
?>