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
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
require_once('config.php');
function __autoload($class_name)
{
$class = explode("_",$class_name);
$path = implode("/",$class).".php";
require_once($path);
}
2. /inc/config.php
<?php
if(!isset($_SESSION)) {
session_start();
}
defined("SITE_URL")
|| define("SITE_URL", "https://".$_SERVER['SERVER_NAME']);
defined("DS")
|| define("DS", DIRECTORY_SEPARATOR);
defined("ROOT_PATH")
|| define("ROOT_PATH", realpath(dirname(__FILE__) . DS."..".DS));
defined("CLASSES_DIR")
|| define("CLASSES_DIR", "classes");
defined("PAGES_DIR")
|| define("PAGES_DIR", "pages");
defined("MOD_DIR")
|| define("MOD_DIR", "mod");
defined("INC_DIR")
|| define("INC_DIR", "inc");
defined("TEMPLATE_DIR")
|| define("TEMPLATE_DIR", "template");
defined("EMAILS_PATH")
|| define("EMAILS_PATH", ROOT_PATH.DS."emails");
defined("CATALOGUE_PATH")
|| define("CATALOGUE_PATH", ROOT_PATH.DS."media".DS."catalogue");
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
class Core
{
public function run()
{
ob_start();
require_once(Url::getPage());
ob_get_flush();
}
}
4. /classes/Url.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()
{
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
require_once('_header.php');
require_once('_footer.php');
?>
6. /pages/error.php
<?php
require_once('_header.php');
echo("<h1>Error</h1>");
require_once('_footer.php');
?>
7. index.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.
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