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
Related
Good afternoon to everyone.
For the past 3 days, I've been struggling with PHP's Autoloading features, which aims to simplify and unify a program's class files, all located in one executing file. For the context, I am currently learning the OOP perspective of PHP from this tutorial videos to not only further understand PHP's OOP understanding before doing a PHP OOP project from college, but also to try to create my own PHP program, so do ELI5 about the solution to me, please.
From what I've learned from the following videos: Video 1 and Video 2, the autoload codes I written from what I've learned appears to work fine, however, it gave two warnings:
Warning: include(/classes/person.php): failed to open stream: No such file or directory in C:\xampp\htdocs\CollegeTimetableApp\includes\autoloader.php on line 12
Warning: include(): Failed opening '/classes/person.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\CollegeTimetableApp\includes\autoloader.php on line 12
And, it gave a fatal error message as follows:
Fatal error: Uncaught Error: Class 'person' not found in C:\xampp\htdocs\CollegeTimetableApp\includes\index.php:33 Stack trace: #0 {main} thrown in C:\xampp\htdocs\CollegeTimetableApp\includes\index.php on line 33
I will include downloadable files so that anyone check and verify it with me.
The Autoloader codes on the autoloading file:
<?php
spl_autoload_register(function($className) {
include str_replace("\\","/","\classes").'/'.str_replace('\\',"/",$className).'.php';
});
?>
Simple executing codes on the index file:
<?php
$person1 = new person();
$person1->SetName("Kai");
echo $person1->name;
?>
My questions: what's wrong, how to create a functioning autoload feature, and are there any additional corrections that can be made from my program?
Thank you.
Try including $_SERVER['DOCUMENT_ROOT'] to your path, as well as the sub folder in that folderwhich contains your app.
<?php
spl_autoload_register(function($className) {
$file = $_SERVER['DOCUMENT_ROOT']; // This is the folder you serve files from
$file .= '/CollegeTimetableApp' // This is the folder in which your app lives
$file .= str_replace("\\", "/", "\classes");
$file .= '/'; // Consider using DIRECTORY_SEPARATOR instead
$file .= str_replace('\\', "/", $className);
$file .= '.php';
include $file;
});
?>
This question already has answers here:
PHP - Failed to open stream : No such file or directory
(10 answers)
Closed 6 years ago.
first sorry my english..
have problem in my project, I can not solve, see.
Warning: require_once(../action/config.php): failed to open stream: No
such file or directory in C:\wamp64\www\maismaranhao\index.php on line
5 Call Stack
Fatal error: require_once(): Failed opening required
'../action/config.php' (include_path='.;C:\php\pear') in
C:\wamp64\www\maismaranhao\index.php on line 5
my index.php is correct, and the settings also. See
<?php
session_start();
require_once "action/config.php";
require_once LIB."system/Utils.class.php";
require_once LIB."system/Data.class.php";
$ACTION = Utils::getAction();
//echo "<pre>"; //var_dump($_GET);exit;
$_GET["DEBUG"] = false;
Utils::utf8_filter(); ...
config.php
<?php
define("DOCUMENT_ROOT",$_SERVER["DOCUMENT_ROOT"]);
define("WORKSPACE",DOCUMENT_ROOT . "action/");
define("TEMP",DOCUMENT_ROOT . "temp/");
define("LIB",WORKSPACE ."lib/");
define("CLASS_PATH",DOCUMENT_ROOT . "classes/");
define("ADMIN_PATH","admin/");
define('SMARTY_PATH',LIB .'external/Smarty/libs/');
define('TEMPLATE_PATH',DOCUMENT_ROOT .'smarty_templates/');
define("URL","localhost");
define("ADMIN_URL",URL . ADMIN_PATH);
define("SITE_NAME","MaisMaranhão");
define("SITE_SLOGAN","Mais Notícias do Maranhão para Você!");
set_include_path(get_include_path() . PATH_SEPARATOR . WORKSPACE .PATH_SEPARATOR . LIB . PATH_SEPARATOR . CLASS_PATH);
?>
The problem is that you are using a relative path in your require_once "action/config.php";. This is wrong, is unreliable, and will generate errors like the one you have encountered.
You should use an absolute path, potentially using _DIR_.
You can read about why this is happening, and how to fix it, in this post: PHP - Failed to open stream : No such file or directory
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
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';
I'm attempting to include files using the $_SERVER['DOCUMENT_ROOT'] variable. So far, every file I've tried to include has thrown an file-not-found error. I assumed that I was just getting the directory wrong, so then I tried to include the currently running script. I'd expect it to recursively include itself until it ran out of stack and fell over.
echo( 'document root = ' . $_SERVER['DOCUMENT_ROOT'] . '<br>' );
echo( 'script name = ' . $_SERVER['SCRIPT_NAME'] . '<br>' );
$szServerPath = $_SERVER['DOCUMENT_ROOT'];
$szIncludePath = $szServerPath . $_SERVER['SCRIPT_NAME'];
echo( "including = " . $szIncludePath );
include( $szIncludePath );
This results in the following output:
document root = /var/httpd/htdocs
script name = /CSRC/Damflask/Main/Articles/index.php
including = /var/httpd/htdocs/CSRC/Damflask/Main/Articles/index.php
Warning: include_once(/var/httpd/htdocs/CSRC/Damflask/Main/Articles/index.php) [function.include]: failed to open stream: No such file or directory in /home/www/glmorriL/CSRC/Damflask/Main/Articles/index.php on line 33
It looks like it still can't find the file. Every other file I've included presented the same error message. Why wouldn't this work?
EDIT: It seems the difference is due to an "alias".
http://php.net/manual/en/reserved.variables.server.php (See Jamie's comment from 2 years ago).
Is there no equivalent path? It looks like DOCUMENT_ROOT is completely useless to me.
Thanks,
G
You can see from the error message that your file path should be:
/home/www/glmorriL/CSRC/Damflask/Main/Articles/index.php
So obviously /var/httpd/htdocs/... won't find it.
Try using the __FILE__ magic constant instead.