title: Fatal error: Call to undefined function finfo_open() in php
body: <p>I am new to php, i have created code for upload images to sql database and retrieve the image using php.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;&lt;title&gt;File Insert&lt;/title&gt;&lt;/head&gt;
  &lt;body&gt;
  &lt;h3&gt;Please Choose a File and click Submit&lt;/h3&gt;
  
  &lt;form enctype="multipart/form-data" action=
  "&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt;
  &lt;input type="hidden" name="MAX_FILE_SIZE" value="10000000" /&gt;
  &lt;input name="userfile" type="file" /&gt;
  &lt;input type="submit" value="Submit" /&gt;
  &lt;/form&gt;
  
  &lt;?php
  
  // check if a file was submitted
  if(!isset($_FILES['userfile']))
  {
      echo '&lt;p&gt;Please select a file&lt;/p&gt;';
  }
  else
  {
      try {
      $msg= upload();  //this will upload your image
      echo $msg;  //Message showing success or failure.
      }
      catch(Exception $e) {
      echo $e-&gt;getMessage();
      echo 'Sorry, could not upload file';
      }
  }
  
  // the upload function
  
  function upload() {
      include "mysqlconnect.php";
      $maxsize = 10000000; //set to approx 10 MB
  
      //check associated error code
      if($_FILES['userfile']['error']==UPLOAD_ERR_OK) {
  
          //check whether file is uploaded with HTTP POST
          if(is_uploaded_file($_FILES['userfile']['tmp_name'])) {    
  
              //checks size of uploaded image on server side
              if( $_FILES['userfile']['size'] &lt; $maxsize) {  
  
                 //checks whether uploaded file is of image type
                //if(strpos(mime_content_type($_FILES['userfile']['tmp_name']),"image")===0) {
                   $finfo = finfo_open(FILEINFO_MIME_TYPE);
                  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 test_image
                      (image, name)
                      VALUES
                      ('{$imgData}', '{$_FILES['userfile']['name']}');";
  
                      // insert the image
                      mysql_query($sql) or die("Error in Query: " . mysql_error());
                      $msg='&lt;p&gt;Image successfully saved in database with id ='. mysql_insert_id().' &lt;/p&gt;';
                  }
                  else
                      $msg="&lt;p&gt;Uploaded file is not an image.&lt;/p&gt;";
              }
               else {
                  // if the file is not less than the maximum allowed, print an error
                  $msg='&lt;div&gt;File exceeds the Maximum File limit&lt;/div&gt;
                  &lt;div&gt;Maximum File limit is '.$maxsize.' bytes&lt;/div&gt;
                  &lt;div&gt;File '.$_FILES['userfile']['name'].' is '.$_FILES['userfile']['size'].
                  ' bytes&lt;/div&gt;&lt;hr /&gt;';
                  }
          }
          else
              $msg="File not uploaded successfully.";
  
      }
      else {
          $msg= file_upload_error_message($_FILES['userfile']['error']);
      }
      return $msg;
  }
  
  // Function to return error message based on error code
  
  function file_upload_error_message($error_code) {
      switch ($error_code) {
          case UPLOAD_ERR_INI_SIZE:
              return 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
          case UPLOAD_ERR_FORM_SIZE:
              return 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
          case UPLOAD_ERR_PARTIAL:
              return 'The uploaded file was only partially uploaded';
          case UPLOAD_ERR_NO_FILE:
              return 'No file was uploaded';
          case UPLOAD_ERR_NO_TMP_DIR:
              return 'Missing a temporary folder';
          case UPLOAD_ERR_CANT_WRITE:
              return 'Failed to write file to disk';
          case UPLOAD_ERR_EXTENSION:
              return 'File upload stopped by extension';
          default:
              return 'Unknown upload error';
      }
  }
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Now i got the error, Fatal error: Call to undefined function finfo_open() on this line </p>
  
  <pre><code>$finfo = finfo_open(FILEINFO_MIME_TYPE); .
  </code></pre>
  
  <p>Can somebody help me to fix this.</p>
  
  <p>Thanks in advance.</p>