Community Support for OpenDocMan (Deprecated)
Error: undefined function mime_content_type() in add.php - Printable Version

+- Community Support for OpenDocMan (Deprecated) (https://forum.opendocman.com)
+-- Forum: OpenDocMan Community Discussion (https://forum.opendocman.com/forum-5.html)
+--- Forum: OpenDocMan Bug Reports (https://forum.opendocman.com/forum-8.html)
+--- Thread: Error: undefined function mime_content_type() in add.php (/thread-595.html)



Error: undefined function mime_content_type() in add.php - Guest - 03-07-2013

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


Re: Error: undefined function mime_content_type() in add.php - Guest - 03-07-2013

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.


Re: Error: undefined function mime_content_type() in add.php - Stephen - 03-07-2013

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;
            }
        }



Re: Error: undefined function mime_content_type() in add.php - plowman - 03-08-2013

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 -->