Codeigniter Absolute path

One function/help that seems to be missing from Codeigniter is an absolute server path, which is needed if you're doing image work.

So here's my way of doing it

Add this line into your application/config/constants.php.

// Absolute path
define('ABSOLUTE_PATH', str_replace('system/','', BASEPATH));

I tend to add all my constants at the top of the file but from my experience it doesn't really matter where your add them.

You could also add them to the index.php however you would need to remember this when you upgrade codeigniter - so probably isn't such a good idea.

// Absolute server path
define ('ABSOLUTE_PATH', dirname(__FILE__));

Is there a better way ?

Let me know !

Happy Coding fellow Igniters !!

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.