Page 1 of 2
PHP Includes
Posted: Mon Jul 24, 2006 6:44 pm
by vchris
I've recently setup php and mysql on my computer after formatting and I get this error when trying to include a leftnav.
Here's the code:
Code: Select all
<?php include("/includes/mf/leftnav.php"); ?>
Warning: main(/includes/mf/leftnav.php) [function.main]: failed to open stream: No such file or directory in c:\Inetpub\wwwroot\MySite\mf\index.php on line 13
Warning: main() [function.include]: Failed opening '/includes/mf/leftnav.php' for inclusion (include_path='.;C:\php5\pear') in c:\Inetpub\wwwroot\MySite\mf\index.php on line 13
I checked mutliple times the path and it is correct. I have tried this for the footer as well and I get the same error. I don't know if I'm doing anything wrong or maybe missing some permissions.
Posted: Mon Jul 24, 2006 6:48 pm
by Burrito
by using a preceding slash (/) you're indicating that the includes folder is at the root of the site.
I'd be willing to bet (given the path of your file) that it's not. If you the includes folder is relative to the file calling it, then you need to use a relative path to it.
Posted: Mon Jul 24, 2006 6:57 pm
by vchris
It is!
Posted: Mon Jul 24, 2006 7:34 pm
by bike5
Try
Code: Select all
<?php include($_SERVER['DOCUMENT_ROOT']."/includes/mf/leftnav.php"); ?>
You can do a
to find out what the important paths really are.
Posted: Mon Jul 24, 2006 8:05 pm
by vchris
bike5 wrote:Try
Code: Select all
<?php include($_SERVER['DOCUMENT_ROOT']."/includes/mf/leftnav.php"); ?>
You can do a
to find out what the important paths really are.
print_r($_SERVER):
Code: Select all
Array ( [ALLUSERSPROFILE] => C:\Documents and Settings\All Users [CLASSPATH] => .;C:\Program Files\QuickTime\QTSystem\QTJava.zip [CommonProgramFiles] => C:\Program Files\Common Files [COMPUTERNAME] => AGENTSMITH [ComSpec] => C:\WINDOWS\system32\cmd.exe [CONTENT_LENGTH] => 0 [FP_NO_HOST_CHECK] => NO [GATEWAY_INTERFACE] => CGI/1.1 [HTTP_ACCEPT] => text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 [HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5 [HTTP_CONNECTION] => keep-alive [HTTP_HOST] => localhost [HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4 [HTTP_ACCEPT_ENCODING] => gzip,deflate [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7 [HTTP_KEEP_ALIVE] => 300 [HTTP_CACHE_CONTROL] => max-age=0 [HTTPS] => off [INSTANCE_ID] => 1 [LOCAL_ADDR] => 127.0.0.1 [NUMBER_OF_PROCESSORS] => 1 [OS] => Windows_NT [Path] => C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Panda Software\Panda Antivirus Platinum\;C:\Program Files\Common Files\Adobe\AGL;C:\Program Files\QuickTime\QTSystem\ [PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH [PROCESSOR_ARCHITECTURE] => x86 [PROCESSOR_IDENTIFIER] => x86 Family 15 Model 2 Stepping 4, GenuineIntel [PROCESSOR_LEVEL] => 15 [PROCESSOR_REVISION] => 0204 [ProgramFiles] => C:\Program Files [QTJAVA] => C:\Program Files\QuickTime\QTSystem\QTJava.zip [REMOTE_ADDR] => 127.0.0.1 [REMOTE_HOST] => 127.0.0.1 [REQUEST_METHOD] => GET [SCRIPT_NAME] => /mf/index.php [SERVER_NAME] => localhost [SERVER_PORT] => 80 [SERVER_PORT_SECURE] => 0 [SERVER_PROTOCOL] => HTTP/1.1 [SERVER_SOFTWARE] => Microsoft-IIS/5.1 [SystemDrive] => C: [SystemRoot] => C:\WINDOWS [TEMP] => C:\WINDOWS\system32\config\SYSTEM~1\LOCALS~1\Temp [TMP] => C:\WINDOWS\system32\config\SYSTEM~1\LOCALS~1\Temp [USERPROFILE] => C:\Documents and Settings\LocalService [windir] => C:\WINDOWS [ORIG_PATH_TRANSLATED] => c:\inetpub\wwwroot\mysite\mf\index.php [ORIG_PATH_INFO] => /mf/index.php [ORIG_SCRIPT_NAME] => /mf/index.php [SCRIPT_FILENAME] => c:\inetpub\wwwroot\mysite\mf\index.php [PHP_SELF] => /mf/index.php [argv] => Array ( ) [argc] => 0 )
Leftnav include:
Code: Select all
Notice: Undefined index: DOCUMENT_ROOT in c:\Inetpub\wwwroot\MySite\mf\index.php on line 14
Warning: main(/includes/mf/leftnav.php) [function.main]: failed to open stream: No such file or directory in c:\Inetpub\wwwroot\MySite\mf\index.php on line 14
Warning: main() [function.include]: Failed opening '/includes/mf/leftnav.php' for inclusion (include_path='.;C:\php5\pear') in c:\Inetpub\wwwroot\MySite\mf\index.php on line 14
Posted: Mon Jul 24, 2006 8:14 pm
by feyd
include('/includes/mf/leftnav.php') would be c:\includes\mf\leftnav.php; is this true? I would doubt it.
Posted: Mon Jul 24, 2006 8:17 pm
by bike5
c:\inetpub\wwwroot\mysite\mf\index.php
It looks like wwwroot is the "webroot", not includes
not sure where ur includes are but I am guessing
Code: Select all
<?php include("/mysite/mf/includes/leftnav.php"); ?>
play around with the path you will get it soon!
Posted: Mon Jul 24, 2006 8:23 pm
by vchris
bike5 wrote:c:\inetpub\wwwroot\mysite\mf\index.php
It looks like wwwroot is the "webroot", not includes
not sure where ur includes are but I am guessing
Code: Select all
<?php include("/mysite/mf/includes/leftnav.php"); ?>
play around with the path you will get it soon!
I changed the webroot folder to mysite so /includes/mf/leftnav.php is correct.
Posted: Mon Jul 24, 2006 8:38 pm
by LiveFree
Why not just remove the / in front of the includes/ folder ?
Posted: Tue Jul 25, 2006 3:05 am
by RobertGonzalez
Code: Select all
include 'includes/mf/leftnav.php';
Posted: Tue Jul 25, 2006 3:17 am
by Ollie Saunders
Give this a go, I'm guessing here:
Code: Select all
include '../includes/mf/leftnav.php';
Posted: Tue Jul 25, 2006 4:06 pm
by vchris
I want absolute paths not relative. It does work with my stylesheet but not for includes.
Posted: Tue Jul 25, 2006 11:35 pm
by RobertGonzalez
Why would relative paths not work with your includes? This should not cause you a problem at all.
Posted: Wed Jul 26, 2006 1:14 am
by John Cartwright
Everah wrote:Why would relative paths not work with your includes? This should not cause you a problem at all.
It may if he's using mod rewrite.
Posted: Wed Jul 26, 2006 1:27 am
by RobertGonzalez
Would the error message show the actual path to the file that could not be included or the rewritten path?
I have never had a problem with declaring a variable in each page of my script called $page_root_path. I set that to path to the root directory and use that var for all of my includes. I have never had a problem with it.
Code: Select all
<?php
$page_root_path = './'; // This file is located in http://www.mysite.com/ root
$page_root_path = './../'; // This file is located in http://www.mysite.com/somefolder/
$page_root_path = './../../'; // This file is located in http://www.mysite.com/somefolder/someotherfolder/
?>
So regardless of where your pages are on your server, your files will always point to root and your includes will always include from there.
Code: Select all
<?php
include $page_root_path . 'includefolder/includefile.php';
?>