user1512181
user1512181

Reputation: 13

require_once fatal error (one more time)

I have created super simple script as same as before when everything worked properly. But somehow it stopped and now everytime I try to require a file it show me an error:

Fatal error: require_once(): Failed opening required 'E:\tools\EasyPHP\www/registry/registry.class.php' (include_path='.;C:\php\pear') in E:\tools\EasyPHP\www\index.php on line 18

My index file:

define("APP_PATH", dirname(__FILE__)."/");
require_once(APP_PATH.'registry/registry.class.php');

That is everything but i still can't load that page.

How should i set it up? I'm using windows for local builds only.

Upvotes: 1

Views: 633

Answers (2)

Jazz
Jazz

Reputation: 1485

define( "APP_PATH", dirname( __FILE__ ) . DIRECTORY_SEPARATOR );
require_once( APP_PATH . 'registry' . DIRECTORY_SEPARATOR . 'registry.class.php' );

The constant DIRECTORY_SEPARATOR evaluates to backslash on Windows systems and forward-slash on *nix systems. This way your code will work without modification on both Windows and Linux environments.

(See the PHP manual on this constant and its friend PATH_SEPARATOR.)

If you're still having trouble, it's possible the file does not exist at that path, or that PHP does not have read permissions to the file.

Upvotes: 3

Niclas Larsson
Niclas Larsson

Reputation: 858

You see in result of your dirname() the string has \ and in your other string you have /, i think you should only have \.

Upvotes: 1

Related Questions