1

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.

Wayne Conrad
  • 103,207
  • 26
  • 155
  • 191
  • file_exists(APP_PATH.'registry/registry.class.php') gives? If false then check APP_PATH.'registry/registry.class.php' against expected path of file – Ingmar Boddington Jul 09 '12 at 14:14
  • 3
    Probably dumb question but does `E:\tools\EasyPHP\www/registry/registry.class.php` exists? – Florent Jul 09 '12 at 14:15
  • yes it is but show me that it didn't even exist. – user1512181 Jul 09 '12 at 14:23
  • ok i have solved this. dreamweaver named file 'registry.class.php.php' and that was probbably my fault that i didn't noticed that. when I recreated files it became working properly. anyway using directory_separator is even better then single slash. – user1512181 Jul 09 '12 at 14:36

2 Answers2

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

Jazz
  • 1,435
  • 1
  • 15
  • 23
  • Failed opening required 'E:\tools\EasyPHP\www\registry\registry.class.php' (include_path='.;C:\php\pear') while file actually exist and it has all save/read/write permissions. – user1512181 Jul 09 '12 at 14:26
1

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

Niclas Larsson
  • 868
  • 5
  • 8
  • i did nothing to it, i set / separator only and backslash has been added to files by system. theres no even way to change it – user1512181 Jul 09 '12 at 14:20
  • In windows you use \ in php in the path to a file, when written in php. So you should write: `define("APP_PATH", dirname(__FILE__)."\"); require_once(APP_PATH.'registry\registry.class.php');` – Niclas Larsson Jul 09 '12 at 14:23