如何检查上传的文件是否是PHP中的SQLite格式文件?

What I want to do is a small web page that a user can upload a SQLite file, but I want to avoid those uploads that aren't SQLite format, so I try to verify it before I execute "move_uploaded_file". Above there's an example of what I've tried to do, but it doesn't work.

function isFileOkay($filedir) { 
  try
  {
    $db = new PDO("sqlite:".$filedir);
    $sql = "PRAGMA schema_version;";

    $ret = $db->query($sql);

    if(!$ret)
    {
      $db = NULL;
      return -1;
    }

    $row = $ret->fetchAll(PDO::FETCH_BOTH);

    $value = (int) $row[0]['schema_version'];

    $db = NULL;
    return $value;
  }
  catch (PDOException $exception) {
    echo $exception->getMessage();
    return -1;
  }
}
...
$test = isFileOkay($_FILES['upload_file']['tmp_name']);
...

The $test variable should be "-1" if the file isn't a SQLite file, or $value. $value = 0 also indicates that the file is not okay, but any value greater than 0 indicates that it is a valid SQLite file. The point is that when I test this code manually inserting a path for $filedir, e.g a file already existing in this machine, the output is correct. But when I try to verify "$_FILES['upload_file']['tmp_name']" it doesn't work, and the page crashes.

I am new at web programming, especially in PHP, so I think there might be a misunderstanding about the $_FILE variable.

You should be able to check the mime type of the uploaded file:

$finfo = new finfo(FILEINFO_MIME_TYPE);

$mime = $finfo->file($_FILES['upload_file']['tmp_name']);

// SQLite is application/x-sqlite3
if ($mime == 'application/x-sqlite3') {
    // Is SQLite
} else {
    // Is something else
}