Community Support for OpenDocMan (Deprecated)

Full Version: Error: undefined function mime_content_type() in add.php
You're currently viewing a stripped down version of our content. View the full version with proper formatting.


I have a fresh install of OpenDocMan v1.2.6.3a on PHP 5.3.18

I've created a few users, categories, and departments for testing so MySQL seems to be working. When I attempt to add a file, I get:

Fatal error: Call to undefined function mime_content_type() in /home/.../DMS/add.php on line 466 [the ellipsis are my substitute for the actual path]

Since Google is my friend, I rooted about and found that
function support is not necessarily enabled, but that a PEARs PHP_Compat install could solve this. I have installed PHP_Compat 1.5.0, but still no luck.

I'm happy to RTFM, but I'm not sure what FM to R. Any suggestions about how to diagnose and correct this?


Oz, in DFW


On further investigation it seems this function is aggressively deprecated in later versions of PHP.

Looks like I'll need to write a patch to use the package.
How about something like this, which might handle newer and older systems:

in function.php:

* Determine the mimetype of a file
* @param file path $filename
* @return string
function getFileMimeType($filename)
  if (function_exists("finfo_file")) {
    // return mime type ala mimetype extension
    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    $mime = finfo_file($finfo, $filename);
    return $mime;
  } else if (function_exists("mime_content_type")) {
    return mime_content_type($filename);
  } else {
    return false;

In add.php (for example):

// check file type
        foreach ($GLOBALS['CONFIG']['allowedFileTypes'] as $thistype)
            if (getFileMimeType($_FILES['file']['tmp_name'][$count]) == $thistype)
                $allowedFile = 1;
            } else
                $allowedFile = 0;
Improved mime type fix here:

<!-- l --><a class="postlink-local" href="">viewtopic.php?f=8&t=880</a><!-- l -->