php - wrong path using 'require' -
since moving website local online , have path problem using require.
i have pages call bootstrap.php this:
require 'inc/bootstrap.php'; and boostrap.php looks this:
<?php spl_autoload_register('app_autoload'); function app_autoload($class){ require "class/$class.php"; } this worked in local.
now, online, following message:
warning: require_once(/home/website/www/class/functions.php): failed open stream: no such file or directory in /home/website/www/inc/bootstrap.php on line 6 fatal error: require_once(): failed opening required '/home/website/www/class/functions.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/website/www/class/functions.php on line 6 so thought, should put absolute path in boostrap.php this:
<?php spl_autoload_register('app_autoload'); function app_autoload($class){ $path = $_server['document_root'] . "class/$class.php"; require_once "$path"; } but exact same error. dont understand why still looking in /home/website/www/inc/bootstrap.php , not following absolute path /home/website/www/class/functions.php ?
edit:
after testing different solutions using absolute pathes, still getting error "no such file or directory in /home/website/www/bootstrap.php: still looking in file instead of directory.
could because using a double require? first require boostrap.php description.php (which works fine) , require class.php boostrap.php (which doesent take absolute path path corresponding file boostrap.php ?
answer:
ok works configuration:
first file using require:
require_once(dirname(__file__). '/inc/bootstrap.php'); and boostrap.php:
require_once(dirname(__file__). "/../class/$class.php");
as said in comments, safe use absolute path instead of 'inc/...', cause relative current class execution path, i.e.:
define ('base_path', dirname(__file__).'/../');then use base_path.{your_path} access files.
i suggest use require_once avoid multiple inclusions.
Comments
Post a Comment