开发者

Problem when including file

开发者 https://www.devze.com 2022-12-27 22:46 出处:网络
<?php //this is intializer.php defined(\'DS\')?null :define(\'DS\',DIRECTORY_SEPARATOR); defined(\'SITE_ROOT\')? null :
<?php

//this is intializer.php
defined('DS')?  null :define('DS',DIRECTORY_SEPARATOR);

defined('SITE_ROOT')? null :
        define('SITE_ROOT',DS.'C:',DS.'wamp',DS.'www',DS.'photo_gallery');

defined('LIB_PATH')?null:define('LIB_PATH',SITE_ROOT.DS.'includes');

require_once(LIB_PATH.DS.'datainfo.php');
require_once(LIB_PATH.DS.'function.php');
require_once(LIB_PATH.DS.'session.php');
require_once(LIB_PATH.DS.'database.php');
require_once(LIB_PATH.DS.'user.php');


//this is other file where i call php file

// ERROR Use of undefined constant LIB_PATH - assumed 'LIB_PATH' in     
//C:\wamp\www\photo_gallery\includes\database.php  on 

//Notice: Use of undefined constant DS - assumed 'DS' in   
//C:\wamp\www\photo_gallery\includes开发者_JAVA技巧\database.php on 

include(LIB_PATH.DS."database.php")

?>

Any ideas as to what might be causing the error above? Thanks in advance for any help.


This isn't directly related to your question, but

define('SITE_ROOT',DS.'C:',DS.'wamp',DS.'www',DS.'photo_gallery');

should probably be

define('SITE_ROOT',DS.'C:'.DS.'wamp'.DS.'www'.DS.'photo_gallery');


You need to do this:

defined('SITE_ROOT')? null : define('SITE_ROOT','C:'.DS.'wamp'.DS.'www',DS.'photo_gallery');

You don't need a DIRECTORY_SEPARATOR before the start of your site root.

You might be better off with this:

defined('SITE_ROOT')? null : define('SITE_ROOT', dirname(__FILE__));

As long as intializer.php is in the root directory


You have to add this line in the database.php

require_once("../../includes/initialise.php");

and remove

require_once (LIB_PATH.DS."config.php");

because the constant LIB_PATH and DS are not accesible unles you add the following code

require_once (LIB_PATH.DS."config.php"); 


Ok, so I think what you are looking for is the actual system file path. To get that you can echo

dirname( __FILE__ ); 

You can do this in any file that you want and it will display the system file path relative to your file. For me it's something like this:

/home2/myusername/public_html/project_name/includes/config.php

so if you are interested in the "project_name" folder you should have something like this:

defined("SITE_ROOT") ? null : define("SITE_ROOT", DS . "home2" . DS . "myusername" . DS . "public_html" . DS . "project_name" );

Then if you are looking for the "includes" folder which will be your library you should have something like this:

defined("LIB_PATH")  ? null : define("LIB_PATH", SITE_ROOT . DS . "includes" );

Hope this helps. I had the exact same problem and this worked for me.

Cheers, Mihai Popa

0

精彩评论

暂无评论...
验证码 换一张
取 消