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.

Guest

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:

Code:
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
Code:
mime_content_type()
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?

TIA,

Oz, in DFW

Guest

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

http://php.net/manual/en/function.mime-content-type.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:

Code:
/**
* 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);
    finfo_close($finfo);
    return $mime;
  } else if (function_exists("mime_content_type")) {
    return mime_content_type($filename);
  } else {
    return false;
  }
}

In add.php (for example):

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

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