Php, Fatal error: require(): Failed opening required

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gintare
    New Member
    • Mar 2007
    • 103

    #1

    Php, Fatal error: require(): Failed opening required

    I am following the book "https://www.packtpub.co m/":
    https://www.packtpub.co m/web-development/cms-design-using-php-and-jquery
    On chapter one the give simple CMS example, but i am getting error when visit http://localhost/cms/

    Warning: require(Page.ph p): failed to open stream: No such file or directory in C:\Bitnami\wamp stack-5.4.38-0\apache2\htdoc s\cms\ww.incs\b asics.php on line 9

    Fatal error: require(): Failed opening required 'Page.php' (include_path=' .;C:/Bitnami/wampstack-5.4.38-0/php/PEAR;C:/Bitnami/wampstack-5.4.38-0/frameworks/smarty/libs') in C:\Bitnami\wamp stack-5.4.38-0\apache2\htdoc s\cms\ww.incs\b asics.php on line 9.

    The file C:\Bitnami\wamp stack-5.4.38-0\apache2\htdoc s\cms\ww.incs\b asics.php
    Code:
    <?php
    session_start();
    function __autoload($name) {
    line 9: require $name . '.php';
    }
    spl_autoload_register("__autoload");
    I have added the line:
    set_include_pat h($_SERVER['DOCUMENT_ROOT'].'/cms/ww.incs/');
    Thus line 9 shifted to line 11:
    Code:
    function __autoload($name) {
    line 11    require $name . '.php';
    }
    spl_autoload_register("__autoload");
    But the error persists:
    Warning: require(Page.ph p): failed to open stream: No such file or directory in C:\Bitnami\wamp stack-5.4.38-0\apache2\htdoc s\cms\ww.incs\b asics.php on line 11

    Fatal error: require(): Failed opening required 'Page.php' (include_path=' C:/Bitnami/wampstack-5.4.38-0/apache2/htdocs/cms/ww.incs/') in C:\Bitnami\wamp stack-5.4.38-0\apache2\htdoc s\cms\ww.incs\b asics.php on line 11
  • gintare
    New Member
    • Mar 2007
    • 103

    #2
    Seems the reason was that i by mistake commented out the last line of the file.
    C:\Bitnami\wamp stack-5.4.38-0\apache2\htdoc s\cms1\ww.incs\ basics.php

    Full file, which now works:
    Code:
    <?php
    session_start();
    function __autoload($name) {
        require $name . '.php';
    }
    spl_autoload_register("__autoload");
    
    /* added http://php.net/manual/en/function.spl-autoload-register.php */
    /*throughs error, because there is not such a thing as Page.php
     * there is only $_SERVER['DOCUMENT_ROOT'].'/cms/folders/Page.php'
     * more: http://stackoverflow.com/questions/5364233/php-fatal-error-failed-opening-required-file
     */
    //set_include_path($_SERVER['DOCUMENT_ROOT'].'/cms1/ww.incs/');
    
    function dbInit(){
    	if(isset($GLOBALS['db']))return $GLOBALS['db'];
    	global $DBVARS;
    	$db=new PDO('mysql:host='.$DBVARS['hostname'].';dbname='.$DBVARS['db_name'],$DBVARS['username'],$DBVARS['password']);
    	$db->query('SET NAMES utf8');
    	$db->num_queries=0;
    	$GLOBALS['db']=$db;
    	return $db;
    }
    function dbQuery($query){
    	$db=dbInit();
    	$q=$db->query($query);
    	$db->num_queries++;
    	return $q;
    }
    function dbRow($query) {
    	$q = dbQuery($query);
    	return $q->fetch(PDO::FETCH_ASSOC);
    }
    define('SCRIPTBASE', $_SERVER['DOCUMENT_ROOT'] . '/cms1/');
    echo 'SCRIPTBASE='.SCRIPTBASE;
    require SCRIPTBASE . 'private/config.php';
    if(!defined('CONFIG_FILE'))define('CONFIG_FILE',SCRIPTBASE.'private/config.php');
    set_include_path(SCRIPTBASE.'ww.php_classes'.PATH_SEPARATOR.get_include_path());

    Comment

    Working...