riteshn Posted December 4, 2006 Share Posted December 4, 2006 HiI have an app whose file structure is like:[code]index.phpcsp-admin/apply.phpcsp-includes/db.php[/code]Now in csp-admin/apply.php, I want to add csp-includes/db.php so at the top, i added:[code]require("./csp-includes/db.php");[/code]and it gives me an error:[code]Warning: require(./csp-includes/db.php) [function.require]: failed to open stream: No such file or directory in /Users/acidity/Sites/csp/csp-admin/apply.php on line 12[/code]But this code in db.php works:[code]require('./index.php');[/code]I saw the docs on REQUIRE at http://us3.php.net/require and there seems to be a problem with the PATH issue. What is the problem with my code?Ritesh Link to comment https://forums.phpfreaks.com/topic/29352-problems-with-path/ Share on other sites More sharing options...
redbullmarky Posted December 4, 2006 Share Posted December 4, 2006 the single dot would imply you're referring to the current directory. personally, i always steer clear of ./ and ../ when dealing with includes.try require($_SERVER['DOCUMENT_ROOT'] . '/csp-includes/db.php') instead, and require($_SERVER['DOCUMENT_ROOT'] . '/index.php') in your db.php Link to comment https://forums.phpfreaks.com/topic/29352-problems-with-path/#findComment-134602 Share on other sites More sharing options...
riteshn Posted December 4, 2006 Author Share Posted December 4, 2006 Even I was thinking of the above method but I have another peculiar problem. I am using Mac OS X with Apache that comes inbuilt in it and PHP module downloaded from: http://www.entropy.ch/software/macosx/Now the inbuilt APACHE is configured like, if I do: http://localhost/username : it takes pages from: /Users/acidity/Sites/ so my files are at: /Users/acidity/Sites/csp/If I do:[code]echo($_SERVER['DOCUMENT_ROOT'])[/code]I get, [code]/Library/WebServer/Documents/[/code]where as it should give probably: [code]/Users/acidity/Sites[/code]so I use the code:[code]require($_SERVER['DOCUMENT_ROOT'] . '/csp-includes/db.php')[/code]I get the error:[code]Fatal error: require() [function.require]: Failed opening required '/Library/WebServer/Documents/csp-includes/db.php' (include_path='.:/usr/local/php5/lib/php') in /Users/acidity/Sites/csp/csp-admin/search.php on line 14[/code]Now, I have 0 idea of Apache, so I am in a fix :(Ritesh Link to comment https://forums.phpfreaks.com/topic/29352-problems-with-path/#findComment-134633 Share on other sites More sharing options...
redbullmarky Posted December 4, 2006 Share Posted December 4, 2006 if you have a file that you pretty much include on EVERY page in your site, you could always define the docroot with one of:[code]<?php// for MacOSXdefine('DOCROOT', '/Users/acidity/Sites'); //change to suit// for otherdefine('DOCROOT', $_SERVER['DOCUMENT_ROOT']);?>[/code]and then use[code]require(DOCROOT . '/csp-include/db.php');[/code]or similar. Link to comment https://forums.phpfreaks.com/topic/29352-problems-with-path/#findComment-134728 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.