16

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.. :( :(

Sharad Saxena
  • 209
  • 1
  • 2
  • 9
  • duplicate, check this answer http://stackoverflow.com/questions/11303033/php-error-thrown-when-including-and-requiring-files/11303128#11303128 – Sergii Stotskyi Sep 03 '12 at 06:32
  • @Serjio Thanks, but the code was working smoothly since eternity. What has caused this problem to occur? I know we can definitely include the files this way.. Then why the error ?? – Sharad Saxena Sep 03 '12 at 06:37
  • 1
    @Spudley nope...I know case sensitivity is annoying but this time it is not causing the error.. I have said that the same code was working fine.. I did not change anything.... But suddenly this error started showing from yesterday.... – Sharad Saxena Sep 03 '12 at 06:40
  • Are you opening the uploadify.php directly? or you are using another script to include it or something? – Miro Markaravanes Sep 03 '12 at 06:49
  • hey... why negative votes?? I am already frustrated by the problem.. now what is all negative voting stuff... – Sharad Saxena Sep 03 '12 at 06:49
  • @MiroMarkarian I am calling the script from jquery.. – Sharad Saxena Sep 03 '12 at 06:51
  • PHP scripts don't care how they were called from the browser. Have you checked with the server administrator to see if there were any changes to php.ini? – Barmar Sep 03 '12 at 08:02
  • @SharadSaxena show your jQuery code pls. And try to call `getcwd()` inside **uploadify.php**. PHP includes files based on value of this function. – Sergii Stotskyi Sep 03 '12 at 08:12

5 Answers5

45

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

SpiderWan
  • 948
  • 10
  • 10
2

In my case I had to write:

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

And that worked!

Hasnat Babur
  • 322
  • 5
  • 14
1

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

0

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 ../

  • actually, I have created a file named initialize.php containing the references.. But still I need to include that initialize.php using ../ Also, **move_uploaded_file** has also stopped working giving error that the folder does not exist...( it was also working fine before) Does this **move_uploaded_file** problem is also related to it? – Sharad Saxena Sep 03 '12 at 06:45
0

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.

Laura
  • 1
  • 1