1

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?

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.