Sanna Bergström
Sanna Bergström

Reputation: 105

Fatal error: Class 'finfo' not found in C:\xampp\htdocs\portfolio\actions\addProject_action.php on line 49

I'm trying to do a fileupload on my website. And I checked in the PHP manual and found this for checking the filetype:

// DO NOT TRUST $_FILES['upfile']['mime'] VALUE !!
// Check MIME Type by yourself.
$finfo = new finfo(FILEINFO_MIME_TYPE); // line 49
if (false === $ext = array_search(
    $finfo->file($_FILES['topImage']['tmp_name']),
    array(
        'jpg' => 'image/jpeg',
        'png' => 'image/png',
        'gif' => 'image/gif',
    ),
    true
)) {
    throw new RuntimeException('Invalid file format.');
}

But with this code I get an php error that says: Fatal error: Class 'finfo' not found in C:\xampp\htdocs\portfolio\actions\addProject_action.php on line 49

Anyone that know why and how to fix this? (apparently I have the wrong PHP version 5.2.0, so I would more like to know if there is a similar good way to do this in erlier PHP versions?)

I have this code inside this:

if(empty($_FILES['topImage'])){
    $errors['topImage'] = "You have to choose a Top Image.";
}else{
    // The code is inside here
}

Upvotes: 1

Views: 2905

Answers (2)

André Fernandes
André Fernandes

Reputation: 21

uncomment the line ;extension=php_fileinfo.dll in the file \xampp\php\php.ini

Upvotes: 2

Việt Anh Nguyễn
Việt Anh Nguyễn

Reputation: 21

i think finfo class is available in PHP >= 5.3.0. maybe your PHP is lower 5.3.0.

Upvotes: 2

Related Questions