Relative path one level up not working in PHP - php

Currently I have the following structure
httpdocs
- system
- templates
Inside templates I have the following line
require_once(__DIR__.'/../system/config.php');
I get the following error
Warning: require_once(/var/www/vhosts/domain/httpdocs/templates/../system/config.php): failed to open stream: No such file or directory in /var/www/vhosts/domain/httpdocs/templates/header.php on line 8
Fatal error: require_once(): Failed opening required '/var/www/vhosts/domain/httpdocs/templates/../system/config.php' (include_path='.:') in /var/www/vhosts/domain/httpdocs/templates/header.php on line 8
As you can see in the path it just adds the two dots (../) as if it is part of the path, while I meant it to go up one level. Is there a PHP setting required to support relative paths or something?
I tried all possible variants of the path in- and excluding the DIR magic constant to no avail. And yes, config.php is present in system.

Deeply ashamed. After I moved the page to another server, I had changed the name of the system folder.

Related

Include cant find directory PHP

i make MVC application (Without frameworks).
I try to include models from folder 'models' in controller, in folder controller.
include("/models/tasks_model.php");
But i get error:
Warning: include(): Failed opening '/models/tasks_model.php' for inclusion (include_path='.') in ...controller\create_task_controller.php on line 3
And
Warning: include(/models/tasks_model.php): failed to open stream: No such file or directory in ...\controller\create_task_controller.php on line 3
You need to fix your PHP paths
include("../models/tasks_model.php");
When you use this code:
include("/models/tasks_model.php");
It looks from the start of your disk because it an absolute path.
../ Goes back one folder from where your file is.

PHP require failing to open stream

I am struggling trying to figure out why my require path link is not working.
My folder setup is the following:
Main domain on server test.example.com.
public_html -> test.example.com -> PHPMailer -> PHPMailerAutoload.php
Since the main domain is test.example.com, I am putting test.example.com in the path url. I have to do this for any link on the site (it was a setup mistake, but I haven't changed it yet).
The way I am trying to access this folder is below:
require 'test.example.com/test.example.com/PHPMailer-master/PHPMailerAutoload.php';
I get the following errors:
Warning: require(test.example.com/PHPMailer-master/PHPMailerAutoload.php): failed to open stream: No such file or directory in /home/example/public_html/test.example.com/php/newsletterSend.php on line 4
Warning: require(test.example.com/test.example.com/PHPMailer-master/PHPMailerAutoload.php): failed to open stream: No such file or directory in /home/example/public_html/test.example.com/php/newsletterSend.php on line 4
Fatal error: require(): Failed opening required 'test.example.com/test.example.com/PHPMailer-master/PHPMailerAutoload.php' (include_path='.:/opt/cpanel/ea-php71/root/usr/share/pear') in /home/example/public_html/test.example.com/php/newsletterSend.php on line 4
I need the link to be an absolute path because the file will be used in different folders.
Does anyone see what I am doing wrong?
it looks like your php is in a directory above the phpMailer folder.. so i think the path would be "../PHPMailer/PHPMailerAutoload.php"
you can use absolute paths if its simpler:
/home/foo/public_html/test.example.com/PHPMailer/PHPMailerAutoload.php
or relative paths if you know where you're starting!
../PHPMailer/PHPMailerAutoload.php

Symlink - require_once doesn't seem to work?

I store my WordPress theme in my Dropbox to use it easily on many machines. Unfortunately require_once()/include_once() doesn't seem to work for me.
Is store original theme at G:\Dropbox\Dropbox\Wordpress\Themes\Blabla\
The symlink is placed at C:\xampp\htdocs\blabla\wp-content\themes\Blabla
When I wanted to require/include any file, eg. C:\xampp\htdocs\blabla\wp-load.php I used to do require_once('../../wp-load.php');
But with symlink all I got is:
Warning: require_once(../../../wp-load.php): failed to
open stream: No such file or directory in
G:\Dropbox\Dropbox\Wordpress\Themes\Blabla\foo\bar.php on line
2 Fatal error: require_once(): Failed
opening required '../../../wp-load.php'
(include_path='.;C:\xampp\php\PEAR') in
G:\Dropbox\Dropbox\Wordpress\Themes\Blabla\foo\bar.php on line
2
Looks like require_once looks for the file within the Dropbox, not symlink context? Is it possible to fix it somehow? I can't use absolute path as I develop on different machines / different OSes and those vary... Any ideas? How does require_once work when it's symlinked? Does it look for required file in both places (original-context & symlink-context)?
How about putting the original file into you Wordpress folder and symlinking to dropbox?
While installing this, you should turn off dropbox on all machines where you did not move the folder yet.

PHP Excel 01simple-download-xlsx.php and 07reader.php giving different output

I am trying to run 2 example of PHPExcel
01simple-download-xlsx.php and 07reader.php
01simple-download-xlsx.php Working Perfect but this example 07reader.php is showing error mentioned below Why can't understand since last 4 hours.
Any one can kindly tell me why this is happening when the file is using same directory structure.
Warning: require_once(../Classes/PHPExcel/IOFactory.php): failed to
open stream: No such file or directory in
C:\xampp\htdocs\manazeschool\software\office_admin\exam_excel\Examples\07reader.php
on line 37
Fatal error: require_once(): Failed opening required
'../Classes/PHPExcel/IOFactory.php'
(include_path='.;C:\xampp\php\PEAR') in
C:\xampp\htdocs\manazeschool\software\office_admin\exam_excel\Examples\07reader.php
on line 37
Some of the examples (such as the 01* files) correctly use an absolute pathname __DIR__ . '../Classes/...' to include the main PHPExcel library, which means you don't need to be in the /Examples directory to run them.
Other examples (07reader.php included) simply use a relative pathname '../Classes/...'to include the main PHPExcel library, which means you do need to be in the /Examples directory to run them.
To resolve the issue, either ensure that you're in the /Examples folder when you run these files, or modify the include to use the absolute pathname.
I believe I've now fixed all of these example files to use the absolute pathname in the development branch on github.

php configuration error

My php files were working fine but today when i check them i get following errors.
Warning: require_once(Connections/deal.php) [function.require-once]: failed to open stream: No such file or directory in C:\complete project\ordering system\orderingcart.php on line 1
Fatal error: require_once() [function.require]: Failed opening required 'Connections/orders.php' (include_path='.;C:\php\pear') in C:\complete project\orderingcart.php on line 1
I don't know how to resolve these errors, where do I start?
It means, the path you gave in require_once() is invalid. You have two options,
1.Checkout whether the path Connections/deal.php is correct or not. Do you have a folder Connections in the folder where this running file is placed? Is there a deal.php inside that folder Connections?
I think your running file path is C:\complete project\ordering system\orderingcart.php. It does not have such a folder and file. So place your Connections folder in C:\complete project\ordering system\ and checkout.
2.Else, You can run the page without fatal error if you change the line to include_once(Connections/deal.php). Functions assosciated with deal.php will be inactivated.
This sounds like the file has either moved OR the file permission have been altered as to prevent the server account (usually www-data) from having access to it.
You might also have better luck by trying to access the file by suppling an absolute path, rather than a relative path, e.g:
<?php
$lines = file("C:\\Documents and Settings\\myfile.txt");
foreach($lines as $line){
echo($line);
}
?>
This file path issue give full file location like
if it is windows
require_once('C:/complete project/Connections/deal.php');
For reference
http://php.net/manual/en/function.realpath.php

Categories