Fatal error: require_once(): Failed opening required - php

i need help on this errer please i intall this script on my easyphp what wrong ?
Warning: require_once(C:/Program Files (x86)/EasyPHP-DevServer-14.1VC9/data/localweb\studentTrans\includes\config.php): failed to open stream: No such file or directory in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\StudentTranscript Processing System in PHP with MySQL\includes\initialize.php on line 21
hello , i need help on this errer please i intall this script on my easyphp what wrong ?
Fatal error: require_once(): Failed opening required 'C:/Program Files (x86)/EasyPHP-DevServer-14.1VC9/data/localweb\studentTrans\includes\config.php' (include_path='.;C:\php\pear') in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\StudentTranscript Processing System in PHP with MySQL\includes\initialize.php on line 21
//define the core paths
/Define them as absolute peths to make sure that require_once works as
expected
//DIRECTORY_SEPARATOR is a PHP Pre-defined constants:
//(\ for windows, / for Unix)
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
defined('SITE_ROOT') ? null : define ('SITE_ROOT',
$_SERVER['DOCUMENT_ROOT'].DS.'studentTrans');
defined('LIB_PATH') ? null : define ('LIB_PATH',SITE_ROOT.DS.'includes');
// load config file first
require_once "config.php";
//load basic functions next so that everything after can use them
require_once "functions.php";
//later here where we are going to put our class session
require_once "session.php";
require_once "member.php";
require_once "student.php";
require_once "student_details.php";
require_once "student_requirements.php";
require_once "department.php";
require_once "sy.php";
require_once "instructor.php";
require_once "instructorclasses.php";
require_once "studSubjects.php";
require_once "grades.php";
require_once "room.php";
//Load Core objects
require_once"database.php";
//load database-related classes

I don't know the relative position of the file you are trying to include, to the file you execute.
However you can get the path using only DIR and then navigate through it.
For example,
$this_directory = __DIR__;
$file_to_include = $this_directory."\includes\config.php";
require_once $file_to_include;
Hope this helps

you have something wrong in the file "initialize.php" included ..

the problem fixed it's was here !!
defined('SITE_ROOT') ? null : define ('SITE_ROOT', $_SERVER['C:\Program Files (x86)\EasyPHP-DevServer- 14.1VC9\data\localweb'].DS.'studentTrans');

Related

include path is not working when referencing another file

I'm having problem with include() and require_once() this is what I have on my script on report-publisher file that resides here :
C:\xampp\htdocs\checklists\reports\report-publishers.php
now i want to include this file:
<?php include("images/report-publisher-completed.php");?>
and the directory of that script is here:
C:\xampp\htdocs\checklists\reports\images\report-publisher-completed.php
it works the problem is in this report-publisher-completed.php i have the following:
require_once("../../includes/database.php");
here is the location of that file: C:\xampp\htdocs\checklists\includes\database.php
so when i run the code I get the following error:
( ! ) Warning: require_once(../../includes/database.php): failed to
open stream: No such file or directory in
C:\xampp\htdocs\checklists\reports\images\report-publisher-completed.php
on line 3
( ! ) Fatal error: require_once(): Failed opening required
'../../includes/database.php' (include_path='C:\xampp\php\PEAR') in
C:\xampp\htdocs\checklists\reports\images\report-publisher-completed.php
on line 3
How can I fix this issue?
Thanks!
Try like this
require_once(dirname(__FILE__).'/../../includes/database.php');
The safer way to include a file is to use a relative path from the current script, using the constant __dir__, like this :
include __dir__ . '/includes/database.php';
So, for your case, probably :
include __dir__ . '/../../includes/database.php';
Try this
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/database.php";
Instead of
require_once("../../includes/database.php");

Not finding any directory

When using PHP require_once it's not finding the specified directory.
Made sure multiple times this directory does exist!
Also tried this with include. What's the problem here?
File structure:
http://prntscr.com/hut7f0
Code:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
class main
{
public static
$test;
}
require_once '/engine/test.class.php';
main::$test = new Test();
?>
Error:
Warning: require_once(/engine/test.class.php): failed to open stream: No such file or directory in C:\xampp\htdocs\includes\loader.php on line 14
Fatal error: require_once(): Failed opening required '/engine/test.class.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\includes\loader.php on line 14
The problem might be due to usage of an absolute path (path starting with /). PHP then tries to find the file at the root of your filesystem. I guess you want to use a relative path here:
require_once 'engine/test.class.php';
You can use the __FILE__ constant to get the base path of your current file:
require_once dirname(__FILE__) . '/engine/test.class.php';

trouble with require_once failed to open stream: No such file or directory

I'm getting the following error when trying to open the index file of a project that I am taking over on:
Warning: require_once(core_services/logging.php): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/app/docroot/www.website.com/index.php on line 7
Fatal error: require_once(): Failed opening required 'core_services/logging.php' (include_path='.:/Applications/XAMPP/xamppfiles/lib/php') in /Applications/XAMPP/xamppfiles/htdocs/app/docroot/www.website.com/index.php on line 7
The code the error refers to looks like this:
7 require_once "core_services/logging.php";
8 $logger=new syslog_class(__FILE__,LOG_DEBUG);
I checked to make sure the filepath exists by defining it and echoing it back as well as the contents of logging.phpin terminal and that returns just fine and when I get the current working directory on line 6, it returns /Applications/XAMPP/xamppfiles/htdocs/app/docroot/www.website.com, which I am assuming is defining my root folder.
Not sure exactly how to go about resolving this problem and if anyone has any ideas on approach, I would love to hear them as my PHP is a bit rusty and lacking outside of the context of wordpress.
edit: approaches I've tried so far
require 'core_services/logging.php';
require '/core_services/logging.php';
require './core_services/logging.php';
require '../core_services/logging.php';
require '/Applications/XAMPP/xamppfiles/htdocs/app/docroot/www.website.com/core_services/logging.php';
require realpath(dirname(__FILE__)) .'/core_services/logging.php';
require(__DIR__"/../core_services/logging.php");
require_once 'core_services/logging.php';
require_once '/core_services/logging.php';
require_once './core_services/logging.php';
require_once '../core_services/logging.php';
require_once '/Applications/XAMPP/xamppfiles/htdocs/app/docroot/www.website.com/core_services/logging.php';
require_once realpath(dirname(__FILE__)) .'/core_services/logging.php';
require_once __DIR__"/../core_services/logging.php";
I have also verified that it is not a permissions issue.
Try specifying full path:
require './core_services/logging.php';
//OR
require '/Applications/XAMPP/xamppfiles/htdocs/app/docroot/www.website.com/core_services/logging.php';

Issues with using PHP Swift Mailer

What I have done:
) Downloaded Swift-4.1.5.tar
) Extracted it
) Uploaded to my host in /public_html/domain/lib using FileZilla
) Made a new script using the code below.
) Opened it in the Browser and I got the following error below
So my question is, how am I getting the error that the file doesn't exist if It's 100% there? Thanks!
<?php
require_once '/public_html/domain/lib/swift_required.php';
?>
Warning: require_once(/public_html/domain/lib/swift_required.php) [function.require-once]: failed to open stream: No such file or directory in /home/myuser/public_html/domain/email.php on line 5
Fatal error: require_once() [function.require]: Failed opening required '/public_html/domain/lib/swift_required.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/myuser/public_html/domain/email.php on line 5
Here's a screenshot of my dir from FileZilla.
http://i.imgur.com/Zsy8y.jpg
This is wrong:
// this is absolute path, just like /home/user or /var/www
require_once '/public_html/domain/lib/swift_required.php';
Use instead:
// this is relative path to the current file
require_once 'public_html/domain/lib/swift_required.php'; //notice: no '/' in the beggining
OR:
// so use this one if you know the whole path to the file
require_once ABSOLUTE_PATH_TO . 'public_html/domain/lib/swift_required.php';
OR:
// or use this one if you don't know the whole path
// or if the path will change (dev machine and production machine)
require_once dirname(__FILE__) . RELATIVE_PATH_TO . 'public_html/domain/lib/swift_required.php';

relative path in require_once doesn't work

I have the following structure
otsg
> class
> authentication.php
> database.php
> user.php
> include
> config.inc.php
> encryption.php
> include.php
> session.php
> index.php
> registration.php
include.php file has the following
ini_set('display_errors', 1);
error_reporting(E_ALL);
ini_set('include_path',ini_get('include_path').':/Applications/MAMP/htdocs/otsg/:');
require_once 'config.inc.php';
require_once '../class/database.php';
require_once '../class/user.php';
require_once 'encryption.php';
require_once 'session.php';
require_once '../class/authentication.php';
and in the index.php page I had included
require_once 'include/include.php';
When I open the page index.php I get the following warning and fatal error. I don't understand what causes this error. When I gave the absolute path it works. But absolute path is not a good idea i believe.
Warning: require_once(../class/database.php) [function.require-once]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/otsg/include/include.php on line 9
Fatal error: require_once() [function.require]: Failed opening required '../class/database.php' (include_path='.:/Applications/MAMP/bin/php5.3/lib/php:/Applications/MAMP/htdocs/otsg/include/:') in /Applications/MAMP/htdocs/otsg/include/include.php on line 9
Use
__DIR__
to get the current path of the script and this should fix your problem.
So:
require_once(__DIR__.'/../class/user.php');
This will prevent cases where you can run a PHP script from a different folder and therefore the relatives paths will not work.
Edit: slash problem fixed
for php version 5.2.17 __DIR__ will not work it will only works with php 5.3
But for older version of php dirname(__FILE__) perfectly
For example write like this
require_once dirname(__FILE__) . '/db_config.php';
In my case it doesn't work, even with __DIR__ or getcwd() it keeps picking the wrong path, I solved by defining a costant in every file I need with the absolute base path of the project:
if(!defined('THISBASEPATH')){ define('THISBASEPATH', '/mypath/'); }
require_once THISBASEPATH.'cache/crud.php';
/*every other require_once you need*/
I have MAMP with php 5.4.10 and my folder hierarchy is basilar:
q.php
w.php
e.php
r.php
cache/a.php
cache/b.php
setting/a.php
setting/b.php
....
I just came across this same problem, where it was all working fine, up until the point I had an includes within another includes.
require_once '../script/pdocrud.php'; //This worked fine up until I had an includes within another includes, then I got this error:
Fatal error: require_once() [function.require]: Failed opening required '../script/pdocrud.php' (include_path='.:/opt/php52/lib/php')
Solution 1. (undesired hardcoding of my public html folder name, but it works):
require_once $_SERVER["DOCUMENT_ROOT"] . '/orders.simplystyles.com/script/pdocrud.php';
Solution 2. (undesired comment above about DIR only working since php 5.3, but it works):
require_once __DIR__. '/../script/pdocrud.php';
Solution 3. (I can't see any downsides, and it works perfectly in my php 5.3):
require_once dirname(__FILE__). '/../script/pdocrud.php';

Categories