views:

36

answers:

2

Hello,

Why is this line not working in constants.php :-

define('FILE_UPLOAD_VIRTUAL_DIR', base_url() . '/uploads/');

base_url() works in all views. Then why not in constants.php?

Thanks in advance :)

+6  A: 

Probably because constants.php is included before the library defining base_url() is.

I don't know CI, but look if there is any chance to define the constant at a later point in the program flow. A CI expert may be able to tell you in more detail where exactly.

Pekka
A: 

Try it like this:

define('FILE_UPLOAD_VIRTUAL_DIR', $_SERVER['DOCUMENT_ROOT'] . '/uploads/');

if you want to define path to file upload directory you don't need url you need path.

KoKo
Be aware that `$_SERVER['DOCUMENT_ROOT']` won't give you the same result as `base_url()` (defined in application's config.php) !
Julien N
Yup, this is not clean practice. When building a CI app, use CI's functions.
Pekka