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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:19:56+00:00 2026-06-15T12:19:56+00:00

Why is the below not recognizing that an image is being uploaded (.jpg)? I

  • 0

Why is the below not recognizing that an image is being uploaded (.jpg)?

I am getting Uploaded file is not an image !!!

$finfo = finfo_open(FILEINFO_MIME_TYPE, 'C:\xampp\php\extras\magic\magic.mime');
if(strpos(finfo_file($finfo, $_FILES['userfile']['tmp_name']),"image")===0) {    

  // prepare the image for insertion
  $imgData =addslashes (file_get_contents($_FILES['userfile']['tmp_name']));

  // put the image in the db...
  // database connection
  mysql_connect($host, $user, $pass) OR DIE (mysql_error());

  // select the db
  mysql_select_db ($db) OR DIE ("Unable to select db".mysql_error());

  // our sql query
  $sql = "INSERT INTO uploaded_images
  (image, name)
  VALUES
  ('{$imgData}', '{$_FILES['userfile']['name']}');";

  // insert the image
  mysql_query($sql) or die("Error in Query: " . mysql_error());
  $msg='<p>Image successfully saved in database with id ='. mysql_insert_id().' </p>';
}
else
  $msg="<p>Uploaded file is not an image.</p>";
  • 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-15T12:19:57+00:00Added an answer on June 15, 2026 at 12:19 pm

    Detecting file types is surprisingly unreliable. Some of the simpler low-level file type detection programs just use the file extension to try and determine the type.

    It’s better to use a tool that specifically works with images, such as imagemagick, if you have the ability to install it on the server that’s running the code. Here’s an example that will tell you whether the file is actually a JPEG image without relying on the file name:

    exec("identify $image_file",$out);
    if(!empty($out)){
        $info = $out[0];
        $info = explode(' ',$out[0]);
        $type = $info[1];
        if($type == 'JPEG'){
            return true;
        }
    }
    

    However, if you don’t have access to install imagemagick you could use the GD library. Failing that, you will either have to trust that the file extension is correct or just trust that the file is an image.

    On a separate note, it’s rarely a good idea to save images in the database, especially if they are then to be delivered as rendered images. MySQL is not designed to be efficient at that. It’s better to store them as files in a directory that can be publicly viewed. Having said that, I don’t know your application so you will be best placed to determine the best course of action.

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

Sidebar

Related Questions

Why does this graphml file below does not render the node color properly in
i'm getting exception on Transformer transformer = tFactory.newTransformer(StreamXSL); but the error below is not
Why does the code below not produce an identical output file to the input
Why is my X method below not being called?! static class Program { private
I have this problem with Safari not recognizing the date format 2012-01-03 (being 2012
My query is like below (not working correctly) SELECT RentACar.dbo.Car.car_id as clm_CAR_ID, RentACar.dbo.Car_Image.car_image_url as
I would like to solve rounding mechanism by using php4,5.2 and below (not 5.3)
Below code not work, but it's work fine for jsf1.2. Now the framework is
The below does not compile: Func<int, int> fac = n => (n <= 1)
The question below is not really a programming question, but more of how can

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.