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

  • Home
  • SEARCH
  • 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 8584099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:41:30+00:00 2026-06-11T21:41:30+00:00

wanna check my uploaded images for right mime type: $user->image = CUploadedFile::getInstance($user, ‘image’); in

  • 0

wanna check my uploaded images for right mime type:

 $user->image = CUploadedFile::getInstance($user, 'image');

in my Validation i check mime type with:

print_r(CFileHelper::getMimeType($this->image));

well, i uploaded a pdf and mime type was application/pdf.
i renamed the pdf to test.jpg, and mime type is now image/jpg which is a problem. i just wanna accept images.

i use the newest versions:
yii-1.1.12.b600af; XAMPP Windows 1.8.0; PHP Version 5.4.4

  • 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-11T21:41:31+00:00Added an answer on June 11, 2026 at 9:41 pm

    Because Yii by default defines mime type according to extension.

    You can see the code

    public static function getMimeType($file,$magicFile=null,$checkExtension=true){//code}
    

    As you see $checkExtension=true.

    You can try like that:

    print_r(CFileHelper::getMimeType($this->image, null, false));
    

    So It will not decide by extension.

    For validation purpose:

    class Item extends CActiveRecord
    {
        public $image;
    
        public function rules()
        {
            return array(
                array('image', 'file', 'mimeTypes'=>'image/gif, image/jpeg'),
            );
        }
    }
    

    Alway use existing things, do not try to re-create.

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

Sidebar

Related Questions

i am looking for code to validate html color codes. wanna check if user
Where to check if type long long is defined? I wanna do something like
Is there any way to check an NSImage's color type in OBJC? I wanna
I wanna check sharepoint title first and see if the lib doesn't have that
In ksh shell, I wanna to check the return value after running a command,
Can I check with you guys if I wanna create an app that can
I wanna check inserted value in excel cell and if value is higher than
i wanna catch all exceptions thrown in a script and then check if they
How can I check for a pixel pattern in PHP? I mean I wanna
I have a login form but I wanna check if the fields are empty

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.