Sharad Saxena
Sharad Saxena

Reputation: 209

PHP require_once error when including file in parent folder

I have the following file structure

-- Plugins
-- inParent.php
---- Uploadify
------ inSame.php
------ Uploadify.php

This function was working smoothly till yesterday. But now, If I try to include the inParent.php in uploadify.php using require_once('../inparent.php), It giving me a silly error..saying...

Warning: require_once(../inParent.php) [function.require-once]: failed to open stream: No such file or directory in /home/user/public_html/plugins/uploadify/uploadify.php on line 3  

But the file definitely exists...

The same code when used to include inSame.php shows no error and works perfectly..

I guessed that there could be file permission problem.. But everything is fine..all the related files have 755/644 permissions.

Also, the move_uploaded_file function has also stopped working.

All the code was working fine till yesterday. I hav'nt changed anything.

I have tried everything and dont know what exactly happened..

Please help me friends.. :( :(

Upvotes: 16

Views: 30417

Answers (5)

Laura
Laura

Reputation: 1

In my case it is really weird:

  1. This Works perfect:

    require('../../the_folder/the_file.php');

  2. But PHP gives an error if i write that as this:

    require('../the_file.php');

Please see that in case 2 i do not go up two steps (../../) and then down to the folder, i directly go up one step (../).

Why is PHP giving the error Failed to open stream: No such file or directory in ... ? It is really weird.

This also works:

require(__DIR__.'/../the_file.php');

Thanks for the TIP.

Upvotes: 0

Richard Nazar
Richard Nazar

Reputation: 11

This question is old, but for people like me who run across it, here is an answer from another part of Stack Overflow.

require_once($_SERVER['DOCUMENT_ROOT'] . '/inParent.php');

PHP require file from top directory

Upvotes: 1

Hasnat Babur
Hasnat Babur

Reputation: 342

In my case I had to write:

require_once dirname( __FILE__ ) . '/' . '../../inParent.php';

And that worked!

Upvotes: 2

SpiderWan
SpiderWan

Reputation: 966

I've googled and found this : require_once __DIR__.'/../inParent.php';

Upvotes: 47

user1203347
user1203347

Reputation: 21

If it was working yesterday and you are certain you did not change anything, then try a server restart first.

Second, on require once try using the full path instead of .. I normally create a file with my root paths and referance those instead of using ./ and ../

Upvotes: 0

Related Questions