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 6559173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:17:26+00:00 2026-05-25T13:17:26+00:00

When I try to process file upload, should I run verification based on file

  • 0

When I try to process file upload, should I run verification based on file MIME type or file-extension?

What are Pros & cons of these 2 ways of file validating?

And, Any other security issues should i be concerned of?

In these days I was relying on MIME type but the answer with most up-votes in this post

File upload issues in PHP says:

Never rely on the MIME type submitted by the browser!

  • 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-05-25T13:17:27+00:00Added an answer on May 25, 2026 at 1:17 pm

    Okay, so to all the geniouses here yapping something about “SCREW EXTENSIONS, CHECK MIME! FILEINFO RLZ!”, I’ve prepared some tutorial:

    1. Download this pretty php logo I drew
    2. View it. Pretty nice, isn’t it?
    3. Rename it to whatever_you_like.php
    4. Put it through all your awesome mime type/whatever checkers
    5. Run it

    In conclusion, you should NEVER EVER EVER rely on MIME type. You web server doesn’t care about MIME type, it determines what to do by EXTENSION, the ultimately downvoted @Col. Shrapnel‘s answer is actually right. Any information provided to you by something checking MIME is absolutely irrelevant to your webserver when it comes to execution.

    EDIT: the not-as-uncommon-code-as-you’d-want-it-to-be that opens a website to this type of attack:

    <?php
    
    $mimetype = mime_content_type($_FILES['file']['tmp_name']);
    if(in_array($mimetype, array('image/jpeg', 'image/gif', 'image/png'))) {
       move_uploaded_file($_FILES['file']['tmp_name'], '/whatever/something/imagedir/' . $_FILES['file']['name']);
       echo 'OK';
    
    } else {
        echo 'Upload a real image, jerk!';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to have an <input type=file> form element that fires the upload process
when I try to fine-tune my process, I see that the waiting channel is
When I try to kill a process in windows with the subprocess.Popen.terminate() or kill()
When I try to start Firefox using Process.Start and ProcessStartInfo (.NET) everything seems to
Sometimes when I try to start Firefox it says a Firefox process is already
We're re-evaluating our database upgrade process for our application to try and remove the
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
So Im trying to implement a file upload functionality where when a user uploads
I am trying to use System.Net.WebClient in a WinForms application to upload a file
Why my file-upload code is not working? I am using commons-fileupload-1.1.1.jar. Also I am

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.