Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7840051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:38:47+00:00 2026-06-02T15:38:47+00:00

How can I define an UPLOAD_DIR constant (or equivalent) so that I can use

  • 0

How can I define an UPLOAD_DIR constant (or equivalent) so that I can use it everywhere?

I tried this as an application configuration parameter

'params'=>array(
            'upload_dir'=>Yii::app()->baseUrl . '/images/uploads/',
),

but Yii::app()->baseUrl cannott be used inside the config file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:38:47+00:00Added an answer on June 2, 2026 at 3:38 pm

    You can do this inside index.php, after the call to Yii::createApplication and before Yii::app()->run():

    define ('UPLOAD_DIR', Yii::app()->baseUrl . '/images/uploads/');
    

    You would then use it just like any other PHP constant, e.g. echo UPLOAD_DIR.

    Edit: When I said after createApplication and before run, I meant exactly that (also, not that there is both a createWebApplication and a createApplication, which is a more generalized version of the former).

    So if you currently have

    Yii::createWebApplication(...)->run();
    

    you have to split it into

    Yii::createWebApplication(...);
    define ('UPLOAD_DIR', Yii::app()->baseUrl . '/images/uploads/');
    Yii::app()->run();
    

    Another option would be to just add another property to your application class. For example, if you have a class MyApplication inside your protected/components directory then you can simply do this:

    class MyApplication extends CWebApplication {
        // ...other code...
        public function getUploadDir() {
            return $this->baseUrl.'/images/uploads/';
        }
    }
    

    You would then access this as Yii::app()->uploadDir.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can define default value in domain by this way : class ProcessingPriority {
I know that one can define an 'expected' exception in JUnit, doing: @Test(expect=MyException.class) public
In Python I can define a function as follows: def func(kw1=None,kw2=None,**kwargs): ... In this
I'm looking for a right-click upload application like RightLoad - an application that can
I will create an ASP.NET Web Application like this; Users can login their own
Say that I have an application where user can upload his avatar, and then
I can define church numerals fairly easy using scheme: > (define f (lambda (x)
In HTML/CSS you can define a style which can be applied to many types
In C# you can define delegates anonymously (even though they are nothing more than
In core.php I can define Configure::write('Routing.admin', 'admin'); and /admin/controller/index will work. but if I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.