1

I might be a bit confused and may need your help with this. I'm inside inc/newsletter.php and want to include a library that is inside lib/mailchimp-api-class

How do I refer to this class file?

I thought it should be …

require_once '../lib/mailchimp-api-class/MCAPI.class.php';

enter image description here

However, this doesn't work … 

Warning: require_once(../lib/mailchimp-api-class/MCAPI.class.php) [function.require-
once]: failed to open stream: No such file or directory in /Users/myname/htdocs/wr/
wp-content/themes/mytheme/inc/newsletter.php on line 6
matt
  • 42,713
  • 103
  • 264
  • 397

3 Answers3

2

If you're in an included file, then the current directory isn't necessarily that of said included file. You can always be absolute about it, though:

require_once dirname(dirname(__FILE__)) . '/lib/mailchimp-api-class/MCAPI.class.php';
Ry-
  • 218,210
  • 55
  • 464
  • 476
0

I think you're using WordPress. This is not working because the relative path is from the starting file.

Try:

require_once dirname(__FILE__).'/../lib/mailchimp-api-class/MCAPI.class.php';

In PHP 5.3 or newer:

you can use __DIR__ instead of dirname(__FILE__)

Ry-
  • 218,210
  • 55
  • 464
  • 476
René Höhle
  • 26,716
  • 22
  • 73
  • 82
  • /Users/myname/htdocs/wr/ wp-content/themes/mytheme/inc/newsletter.php on line 6 wp-content sounds a bit like workpress. – René Höhle Dec 08 '12 at 17:08
0

Try using absolute path:

require_once $_SERVER['DOCUMENT_ROOT'] . '/wr/wp-content/themes/mytheme/lib/mailchimp-api-class/MCAPI.class.php';
jacoz
  • 3,508
  • 5
  • 26
  • 42