Web application not finding file in what appears to be the correct path

I tried to reorganise my facebook application files into better folders and now when I try to load my application on facebook it throws the following error:

Warning: require_once(../scripts/mysql_connect.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\<root folder>\Model\Database.php on line 3

Fatal error: require_once() [function.require]: Failed opening required '../scripts/mysql_connect.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\<root folder>\Model\Database.php on line 3 

The second error is a result of the failure of the first one I think. The weird thing is that my program works perfectly fine when I'm accessing through the localhost url in the browser but when I run it through facebook it throws this error.

In my root folder I have a "Model" folder where the Database.php file is kept and a "scripts" folder where the mysql_connect.php file is kept. I have tried clearing my cache on the browser and using private browsing but it is still throwing this error.

Does anyone know what could be wrong?

EDIT: Sorry this does not seem to be working in localhost either now! One thing I think is weird is that it says "failed to open stream : NO SUCH FILE OR DIRECTORY IN" and then lists the database.php path. Why is it looking in there?

I use the line require_once('../scripts/mysql_connect.php'); at the top of my Database.php file to include it.


It seems that on the server there is a different working directory. Something like the following owuld be a quick fix

dirname(__FILE__) . '/../scripts/mysql_connect.php'

Ok I've fixed this, but I'm still unsure why it was a problem. In my root folder I have two folders: scripts, and Model. I have a database.php file in my Model folder which has the following line of code in:


For some reason this did not work, but by replacing the line with:


This started working again! Just thought I would post the solution. Does anyone know why the other way failed? I thought the ".." just makes it go up one level in the folder hierarchy i.e. to the root folder in this case, and then follow the path which would have taken it to the file...

EDIT: This appears to only have solved it for localhost and not through Facebook...

Do you have permission to edit your php.ini file? One solution would be to find the line with the include path (you'll notice it has C:\xampp\php\PEAR in there already). Include the full path to the "scripts" folder you're referencing, then you can change the php code to read:


PHP will be able to find this file since it's in the include path. Just make sure that if you start adding several include paths that you shouldn't have a file named mysql_connect.php in two or more of the different include paths because you'll most likely get errors. Hope this helps. It definitely makes for some cleaner code.

Need Your Help

Getting location information of Android phones connected to a wifi access point

android geolocation wifi signal-strength

I am trying to get the location information of Android phones connected to a particular wifi access point/hotspot which is another Android device. I know how to obtain location information for a

SWT PrintDialog driver preferences / customize the printdialog

swt driver preferences printdialog

I would like to create a custom SWT PrintDialog. However it seems not possible.