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
Share on other sites

OK, will do.

 

I just wanted to avoid using a full path so that I could move my code without having to change all the paths but hey, if that will work, it's worth the extra 5 mins work ;)

 

I'll have a look at the include_dir though!

 

Thanks!

Link to comment
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.