Jump to content

'require' problems - failed to open stream


eco

Recommended Posts

Hi guys,

 

I'm back with another question... I hope I can give back to the forum once I get the hang of PHP ;)

 

I am getting the following warning when I execute my PHP script from any other place than the Class folder

 

Warning: require(../config.php): failed to open stream: No such file or directory in /root/API/Class/API.php on line 30

 

Fatal error: require(): Failed opening required '../config.php' (include_path='.:/usr/share/php5:/usr/share/php') in /root/API/Class/API.php on line 30

 

The following is the Class API

<?php

Class API
{        
        public function GetUser($name)          
        {
                require '../config.php';
                [...]
        }

        public function ListUsers()
        {
                require '../config.php';
                [...]        
         }

 

The file is indeed where it's meant to be ie '../config.php' but I admit having trouble figuring out require/require_once, etc.

 

Any help or pointers to documentation are welcome :)

-eco

Link to comment
https://forums.phpfreaks.com/topic/162648-require-problems-failed-to-open-stream/
Share on other sites

If you have a configuration file that loads with each page just create a variable containing the full path so if you ever need to change it you can do so in one place.

 

Could you give me a quick example?  I don't get what you mean.

The file is a restricted file that holds the user and password.  This is only accessed by a couple of classes.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.