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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:20:04+00:00 2026-06-16T17:20:04+00:00

Possible Duplicate: How to check if an uploaded file is an image without mime

  • 0

Possible Duplicate:
How to check if an uploaded file is an image without mime type?
uploading, processing, storing and delivering user-provided files and images

i have image sharing script, i made half of it.
the user can rename any php or cgi file to .jpg and upload it and it upload succfully

How to prevent uploading such fake images?

here is my way to check the file type

 $userfile_type = $_FILES['file']['type']; 

and when i rename php file to php.jpg it can be uploaded easly.

  • 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-16T17:20:06+00:00Added an answer on June 16, 2026 at 5:20 pm
    // return mime type ala mimetype extension
    $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $type = finfo_file($finfo, $tmp_name);
    finfo_close($finfo);
    

    This is the server giving you the type of the file and not the browser as in your example.

    With GD you can do something like
    getimagesize()
    which returns zero if the file is not an image

    EDIT: “getimagesize is not a GD library function. It’s native to PHP” Thanks Vivek

    Happy coding !!

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

Sidebar

Related Questions

Possible Duplicate: uploaded file type check by PHP I used the below script for
Possible Duplicate: How to check file types of uploaded files in PHP? I have
Possible Duplicate: How to check file types of uploaded files in PHP? Creating a
Possible Duplicate: How to detect if a user uploaded a file larger than post_max_size?
Possible Duplicate: Check synchronously if file/directory exists in Node.js For example, i have a
Possible Duplicate: Check whether user has my chrome extension installed is there any easy
Possible Duplicate: Check if image exists with given url using jquery Change image source
Possible Duplicate: Check whether user has my chrome extension installed A little background. I'm
Possible Duplicate: Check if user is logged in New Facebook API ive implemented facebook
Possible Duplicate: How to check a file if exists with wildcard in Java? 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.