including a php file.

The following file will work just fine in my localhost

cron_test.php
[php]require("./…/domain.com/config.php");[/php]
but when uploaded to my live server it gives me this:

Warning: require(./../domain.com/config.php): failed to open stream: No such file or directory in /home/username/cron/cron_test.php on line 5

my files structure look like the following:

*cron/
-cron_test.php
*web root/
-index.php
-config.php
-blah.php
-blah.php

I know on some forums they say you have to use DIR or Filepath something like that not quite sure.
but why does this happen?, It is possible to include without using an extra php function?

Your localhost is starting at the server root directory, your other server is not.

Quick way is to set the path. Something like:

[php]require("/home/username/cron/config.php");[/php]

This way finds the path on its own:
(My setup)
[php]$path = realpath(dirname(FILE)) . DIRECTORY_SEPARATOR;
require_once($path . “config/database.php”);
require_once($path . “config/functions.php”);[/php]

This is the answer I was looking for.

I guess I will have to stick to dirname(FILE) if I want to update files from local to server and vice versa.

Thanks Kevin

Sponsor our Newsletter | Privacy Policy | Terms of Service