Fatal Error- Require_once - php

I am getting the following error:
Warning: require_once(C:\xampp\htdocs\mvc\public\views\home\init.php): failed to open stream: No such file or directory in C:\xampp\htdocs\mvc\public\index.php on line 3
Fatal error: require_once(): Failed opening required 'C:\xampp\htdocs\mvc\public\views\home\init.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\mvc\public\index.php on line 3
In Index.php, my code is
<?php
require_once __DIR__ . '\views\home\init.php';
$app= new app;
?>
In init.php, my code is
<?php require_once __DIR__ . '\core\app.php';
require_once __DIR__ . '\core\controller.php';
In controller.php:
<?php
class controller
{
}
?>
In app.php
<?php
class app
{
public function _construct()
{
echo 'now what';
}
}
?>
My folder paths are:
htdocs\mvc\app\views\home\init.php
htdocs\mvc\app\core\app.php & controller.php
htdocs\mvc\public\index.php
Anybody please help? i have tried require_once (_DIR . ""); as well but not working.

Try this:
First do echo for the file path in index.php file like -
echo __DIR__ . '/views/home/init.php';
And then check whether the path is correct or not. If not, then change it accordingly and then use the path in require_once.

You can also test the permission of directory and file itself. There could be an issue of executing file if permission is read only.

restore the index.php file in your public folder.... the error will clear out.

Put index.php file in your public folder.... the error will clear out.
tested and verified

Related

include_path won't work on PhpStorm

I have a construct function where I am using include_path, the function looks like this :
public function __construct()
{
$url = $this->parseUrl();
if(file_exists('application\controllers'.$url[0].'.php')){
$this->controller=$url[0];
unset($url[0]);
}
require_once 'application\controllers'.$this->controller.'.php';
echo $this->controller;
}
Unfortunately, when I try to load an existing controller url like this one http://localhost/project/public_html/home I get the following error :
Warning: require_once(application\controllers home.php): failed to open stream: No such file or directory in C:\xampp\htdocs\project\application\core\App.php on line 24
Fatal error: require_once(): Failed opening required 'application\controllers home.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\project\application\core\App.php on line 24
I followed the documentation and I included the paths :
C:\xampp\htdocs\project\application
and
C:\xampp\htdocs\project\application\controllers
but I am still getting the error and I am just clueless why... can someone help me?
But you have a space in the path...is that normal?
Can you try with 'application\controllers' (without space there) please?
And controllershome.php is the name of file, or controllers/home.php?

PHP Required Once Error when opening file

I am getting the following error from a Windows server:
Warning: require_once(../../conf/config.php): failed to open stream: No such file or directory in \WDP\DFS\30\6\3\2\3039591236\user\sites\5213291.site\www\webmap\inc\class\conf.php on line 2
Fatal error: require_once(): Failed opening required '../../conf/config.php' (include_path='.;C:\php\pear') in \WDP\DFS\30\6\3\2\3039591236\user\sites\5213291.site\www\webmap\inc\class\conf.php on line 2*******
This is a simple query to MYSQL table on a Windows server. I have the files in www/webmap. Here is the relevant part of the config.php
<?php
require_once(dirname(dirname(__FILE__)) . '/inc/class/csite.php');
require_once(dirname(dirname(__FILE__)) . '/inc/class/users.php');
require_once(dirname(dirname(__FILE__)) . '/inc/class/dbc.php');
require_once(dirname(dirname(__FILE__)) . '/inc/class/resize.php');
require_once(dirname(dirname(__FILE__)) . '/inc/class/func.php');
My understanding is that the config.php is found as I included:
echo "Does file exist?". file_exists($file) ? 'true' : 'false';
echo "Is it readable?".is_readable($file) ? 'true' : 'false'; require_once $file;
which returns "true, true"
The error in your program is located in this file.
WDP\DFS\30\6\3\2\3039591236\user\sites\5213291.site\www\webmap\inc\class\conf.php
On line 2...
require_once '../../conf/config.php';
Based on this error message, the file your program is looking for is this...
WDP\DFS\30\6\3\2\3039591236\user\sites\5213291.site\www\webmap\conf\config.php
To fix your program, you need to make sure that your require_once function is properly pointing to the config.php file you're looking for.
File Path Examples
\www\conf\config.php
require_once '../../../conf/config.php';
\www\webmap\conf\config.php
require_once '../../conf/config.php';
\www\webmap\inc\conf\config.php
require_once '../conf/config.php';
\www\webmap\inc\class\conf\config.php
require_once 'conf/config.php';
If things are getting rough using ../'s, try finding your file from the root by beginning your path with a forward slash.
require_once '/webmap/inc/conf/config.php';
You can also try this to make sure you are reading from the proper relative directory:
require_once dirname(__FILE__) . '/../../conf/config.php';
My final offer:
Based on the file location's you've supplied in the comments, I can only recommend that you try one of these sets.
require_once '../../conf/config.php';
require_once '../conn.php';
require_once '/webmap/conf/config.php';
require_once '/webmap/inc/conn.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/webmap/conf/config.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/webmap/inc/conn.php';

move_uploaded_file(...): failed to open stream: No such file or directory

I try to insert images in my database with PHP and MySQL with a temporary folder.
I use laravel and this is my controller:
if(isset($_FILES['img_masc']))
{
$img=$_FILES['img_masc']['name'];
$ruta= $_FILES['img_masc']['tmp_name'];
}
$destino='../../../Perf_Masc/'.$img;
$masc->img=$destino;
//copy($ruta, $destino);
move_uploaded_file($ruta, $destino); //line 49
This is my view:
<form method="POST" action="/RegMasc" enctype= "multipart/form-data" >
<div>
<input required name="img_masc" type="file"/>
</div>
This is my error:
ErrorException in line 49:
move_uploaded_file(../../../Perf_Masc/AF5.jpg): failed to open stream: No such file or directory
I try with so much things and also with the copy function and is not working anyway
In your Config file or some common file define your path as below
define('DOCROOT', $_SERVER['DOCUMENT_ROOT'].'<YOUR PROJECT DIRECTORY>/');
Include this common php in all your class file.
Then
$destino= DOCROOT.'Perf_Masc/'.$img; // HERE DOCROOT is defined in config.
Change your forward slash to a back slash.
First define these
//Define back slash so that you can use it anywhere later
defined("DS") ? null : define("DS", DIRECTORY_SEPARATOR);
// Define your website siteroot
defined("SITE_ROOT") ? null : define("SITE_ROOT", "C:".DS."wamp".DS."www".DS."your_website");
Now move your files
$file_name=$_FILES['file']['name'];
$file_tmp=$_FILES['file']['tmp_name'];
$file_upload_to=SITE_ROOT . DS . "Perf_Masc";
move_uploaded_files($file_tmp, $file_upload_to . DS . $file_name);
If you have a hard time defining the root of your website, you can create a php file in your root directory and then echo __DIR__ for PHP 5.3 or later, for earlier versions use echo dirname(__FILE__).

php __autoload() is not working

I haven't seen any error in my files but when I run my code it shows me the following error:
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
My code is:
classes/Core.php
<?php
class Core {
public function run() {
ob_start();
require_once(Url::getPage());
ob_get_flush();
}
}
inc/autoload.php
<?php
require_once('config.php');
function __autoload($class_name) {
$class = explode("_", $class_name);
$path = implode("/", $class).".php";
require_once($path);
}
index.php
<?php
require_once('inc/autoload.php');
$core = new Core();
$core->run();
I know it's a bit late. I was researching on this because I had the same problem. This is what i tried and it worked for me.
// this code is for the inc/autoload.php file.
define('__ROOT__', dirname(dirname(__FILE__)));
require_once(dirname(__FILE__) . "/config.php");
//require_once(inc/config.php);
function __autoload($className){
$class = explode("_",$className);
$path = implode("/",$class).".php";
require_once($path);
}
Please I just started learning PHP and i stand corrected by you guys.
I hope this helps.
Your Core class is apparently defined at:
C:\xampp\htdocs\completed\classes\Core.php
But you attempt to load this file:
C:\xampp\htdocs\completed\Core.php
It isn't a good idea to build a class auto-loader that works with relative paths*. I suggest you add a prefix here to build an absolute path:
$path = implode("/", $class).".php";
E.g.:
$path = __DIR__ . '/../classes/' . implode("/", $class).".php";
(*) Among other reasons, because relative paths in PHP are relative to the main script (rather than the file when path usage happens) so the source directory depends on what script you load autoload.php from.
I've faced the same problem with yours. I think it's late for you. But may be it's helpful for others.
I didn't included the config.php file in autoload.php file
inc/autoload.php
//require_once('config.php');
I included config.php file in the index.php like this:
index.php
require_once('inc/config.php');
require_once('inc/autoload.php');
And it's worked fore me, I hope this for you, too :). Thanks for your time to read my comment.
because in same folder
require_once('inc/autoload.php');
require_once('config.php');
so.. i think may be should like this
require_once('inc/config.php');

XAMPP Path to include in PHP and AJAX

After reading tons of articles and trying out a lot code I coudn't make it work to include a php file form my localhost. And know I cannot even specify a path in javascript code like
xmlhttp.open("GET","/DB/ajax/ajaxDeleteRow.php?q="+commentId,true);
I would like to include the file: drawTableSqlString.php which is in the same folder as my file: CommentTableAndDeleteAjax.php. they are in the folder: C:\xampp\htdocs\DB\ajax
What I tried so far:
1.
echo get_include_path(); and i got displayed: .;C:\xampp\php\PEAR
then I tried to copy my file into that folder --> didn't work.
echo dirname(drawTableSqlString.php);
I got an error:
Notice: Use of undefined constant drawTableSqlString - assumed 'drawTableSqlString' in C:\xampp\htdocs\DB\ajax\CommentTableAndDeleteAjax.php on line 36
3.
after changing path in php.ini from "include_path=".;C:\xampp\htdocs"" to include_path=".;C:\xampp\php\PEAR"
i tried:
include ('\DB\ajax\drawTableSqlString.php');
include ('DB\ajax\drawTableSqlString.php');
gives an error as aways which looks like this:
Warning: include(\DB\ajax\drawTableSqlString.php): failed to open
stream: No such file or directory in
C:\xampp\htdocs\DB\ajax\CommentTableAndDeleteAjax.php on line 33
Warning: include(): Failed opening '\DB\ajax\drawTableSqlString.php'
for inclusion (include_path='.;C:\xampp\htdocs') in
C:\xampp\htdocs\DB\ajax\CommentTableAndDeleteAjax.php on line 33
Based on other forum entries I also tried all that code below but nothing worked:
//************************** include DB connection INFOS
//$xajax_dir = 'C:\\xampp\\htdocs\\DB\\ajax';
//include( $xajax_dir . DIRECTORY_SEPARATOR . 'drawTableSqlString.php' );
//include('./localhost/DB/ajax/CommentTableAndDeleteAjax.php' );
//include('localhost/DB/ajax/CommentTableAndDeleteAjax.php' );
//include('./DB/ajax/CommentTableAndDeleteAjax.php' );
//include('DB/ajax/CommentTableAndDeleteAjax.php' );
//include('C:/xampp/htdocs/localhost/DB/ajax/drawTableSqlString.php' );
//include_path = ('.;C:\xampp\php\PEAR','C:\xampp\htdocs\DB\ajax\drawTableSqlString.php');
//include('127.0.0.1/DB/ajax/CommentTableAndDeleteAjax.php' );
//include('C:\xampp\htdocs\DB\ajax\drawTableSqlString.php');
//FROM http://stackoverflow.com/questions/17003614/including-files-from-include-path-not-working-as-expected
//include_once ('/DB/ajax/drawTableSqlString');
//include_once("C:/xampp/htdocs/DB/ajax/drawTableSqlString.php");
// include __DIR__ . 'drawTableSqlString.php';
// include '../drawTableSqlString.php';
//include('http://127.0.0.1/DB/ajax/CommentTableAndDeleteAjax.php' );
//$xajax_dir = 'C:\\xampp\\htdocs\\DB\\ajax';
//include( $xajax_dir . DIRECTORY_SEPARATOR . 'drawTableSqlString.php' );
//include ('drawTableSqlString.php');
//include_path=".;c:\php\includes"
//http://www.php.net/manual/en/ini.core.php#ini.include-path
//set_include_path(".;c:\xampp\htdocs\DB\ajax");
//include ('drawTableSqlString.php');
//echo get_include_path();
Any help would be really apreciated.
EDIT:
Since I changed some parts of the php.ini I get an error when staring XAMPP saying:
Fatal Error: Directive 'register_globals' is no longer available in
PHP

Categories