tags:

views:

271

answers:

3

In my Xampp I can do :

require_once('../myFile.php');

And it works.

When I upload the file that do the require_once, it doesn't work.

Here is the error on the server:

Warning: require_once(../myFile.php) [function.require-once]: failed to open stream: No such file or directory in /home/xxx/public_html/yyyy/testinclude.php on line 11

Fatal error: require_once() [function.require]: Failed opening required '../myFile.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/xxx/public_html/yyyy/testinclude.php on line 11

Any idea?

A: 

If myFile.php doesn't exist in directory public_html, then it won't work.

If you want it to look in the same directory as you, try require_once('./myFile.php')

Chacha102
Not true, he is including `../myFile.php`, therefore the file must reside in `/home/xxx/public_html/`
Andrew Moore
it does exist... I told in the question that it works on the Windows Machine and the file on the server is used in the yyyy directory...
Daok
Andrew, I don't see the mistake? ;)
Chacha102
+4  A: 

One possible reason why its not working is that your file-casing isn't exactly the same.

In UNIX, file paths are case-sensitive. This is not the case in WIN. So, if you are including ../myFile.php, your file must be name myFile.php, not myfile.php.


Also, include are always including files according to the current path. Consider these two files.

/home/xxx/public_html/first.php

<?php include('dir/second.php'); ?>

/home/xxx/public_html/dir/second.php

<?php include('third.php'); ?>

When running first.php, the second file will include /home/xxx/public_html/third.php.

When running dir/second.php directly, it will include /home/xxx/public_html/dir/third.php.

If your include must always be relative to the current file, use the following:

include(dirname(__FILE__) . '/third.php');

Using the above code fragment, dir/second.php will always include /home/xxx/public_html/dir/third.php regardless of the current directory.

Andrew Moore
YOU GOT IT!!!!! +1 and the answer! WOW nice job dude the name of the file was about 35 characters long and one 'b' was there instead of 'B' in the middle of it! :)
Daok
A: 

Where is your myFile.php file relative to your testinclude.php file?

If you're requiring it in ../ then myFile.php needs to be one level higher than testinclude.php (i.e. in /home/xxx/public_html/)

mopoke