Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Basically i am learning php i have great knowledge about procedural PHP, now i am using "Udemy.com" tutorials to learn OOPS and work with Framework, so i am following my Udemy teacher what he is doing, and i think the tutor is doing perfect coding because when i run that coding on my hosting that works fine, so i am sharing my whole coding please check and tell me the solution, The only problem is that when i tried to access my index.php file the following error occurs.

My Project Path: C://xampp/htdocs/project-name


PHP
Warning: require_once(Core.php): failed to open stream: No such file or directory in C:\xampp\htdocs\completed\inc\autoload.php on line 7

Fatal error: require_once(): Failed opening required 'Core.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\completed\inc\autoload.php on line 7


Project Coding:


1. /inc/autoload.php

PHP
<?php
require_once('config.php');
function __autoload($class_name)
{
$class = explode("_",$class_name);
$path = implode("/",$class).".php";
require_once($path);
}


2. /inc/config.php

PHP
<?php
if(!isset($_SESSION)) {
    session_start();
}

// site domain name with http
defined("SITE_URL")
|| define("SITE_URL", "https://".$_SERVER['SERVER_NAME']);

// directory separator
defined("DS")
|| define("DS", DIRECTORY_SEPARATOR);

// root path
defined("ROOT_PATH")
|| define("ROOT_PATH", realpath(dirname(__FILE__) . DS."..".DS));

// classes folder
defined("CLASSES_DIR")
|| define("CLASSES_DIR", "classes");

// pages directory
defined("PAGES_DIR")
|| define("PAGES_DIR", "pages");

// modules folder
defined("MOD_DIR")
|| define("MOD_DIR", "mod");

// inc folder
defined("INC_DIR")
|| define("INC_DIR", "inc");

// templates folder
defined("TEMPLATE_DIR")
|| define("TEMPLATE_DIR", "template");

// emails path
defined("EMAILS_PATH")
|| define("EMAILS_PATH", ROOT_PATH.DS."emails");

// catalogue images path
defined("CATALOGUE_PATH")
|| define("CATALOGUE_PATH", ROOT_PATH.DS."media".DS."catalogue");

// add all above directories to the include path
ini_set('include_path',implode(PATH_SEPARATOR, array(
    realpath(ROOT_PATH.DS.CLASSES_DIR),
    realpath(ROOT_PATH.DS.PAGES_DIR),
    realpath(ROOT_PATH.DS.MOD_DIR),
    realpath(ROOT_PATH.DS.INC_DIR),
    realpath(ROOT_PATH.DS.TEMPLATE_DIR),
    ini_get('include_path')
)));


3. /classes/Core.php

PHP
<?php
class Core
{
public function run()
{
ob_start();
        require_once(Url::getPage());
        ob_get_flush();
}
}


4. /classes/Url.php

PHP
<?php
class Url
{
    public static $_page = "page";
    public static $_folder = PAGES_DIR;
    public static $_prams = array();
    public static function getParam($par)
    {
        return isset($_GET[$par]) && $_GET[$par] != "" ? $_GET[$par] : null;
    }
    public static function cPage() // yeh current page return karta hai.
    {
        return isset($_GET[self::$_page]) ? $_GET[self::$_page] : 'index';
    }
    public static function getPage()
    {
        $page = self::$_folder.DS.self::cPage().".php";
        $error = self::$_folder.DS."error.php";
        return is_file($page) ? $page : $error;
    }
    public static function getAll()
    {
        if(!empty($_GET))
        {
            foreach($_GET as $key => $value)
            {
                if(!empty($value))
                {
                    self::$_prams[$key] = $value;
                }
            }
        }
    }
}


5. /pages/index.php

PHP
<?php
require_once('_header.php');
require_once('_footer.php');
?>


6. /pages/error.php

PHP
<?php
require_once('_header.php');
echo("<h1>Error</h1>");
require_once('_footer.php');
?>


7. index.php

PHP
<?php
require_once('inc/autoload.php');
$core =  new Core();
$core->run();
?>


Above are the codes for whole project when i run this i got following error, How can i resolve, Kindly Help.

PHP
Warning: require_once(Core.php): failed to open stream: No such file or directory in C:\xampp\htdocs\completed\inc\autoload.php on line 7

Fatal error: require_once(): Failed opening required 'Core.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\completed\inc\autoload.php on line 7
Posted
Updated 20-Feb-16 2:45am
v2

1 solution

Thanks to all, The problem is solved by making virtual host sub domain in xampp.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900