Unable to download uploaded documents

Running both 7.6.6 and 7.7.3 on Windows 2012 R2 using IIS 8.5 using PHP 5.6.22

We are able to create a document in SuiteCRM and upload a file. However, when it comes to downloading the file, we get the following errors (after turning the php.ini display_errors to On):

Notice: Undefined offset: 1 in C:\inetpub\wwwroot\SuiteCRM_Test\download.php on line 110

Fatal error: Call to undefined function mime_content_type() in C:\inetpub\wwwroot\SuiteCRM_Test\download.php on line 174

The same error is displayed whether running our test 7.7.3 instance or production 7.6.6.

Many thanks in advance,
Yianni

1 Like

you need to activate the extension mime_content_file

http://stackoverflow.com/questions/14809054/mime-content-type-function-not-working

best regards

2 Likes

@mikebeck Thank you!

I’m running CentOS on PHP 5.6.24, what is the solution for non-windows users?
sieberta

I upgraded to PHP v. 7.0.x… all is well in the world again.

sieberta

sieberta, sorry for the late reply, I’m glad that you got it working, I think that in PHP 5.6 that extension was deprecated then added in again in 7.0

best regards

1 Like

Hello everyone. I am getting the same errors.

My environment is as follows:

Server Information
Operating System CentOS release 5.11 (Final)
Kernel Version 2.6.18-194.3.1.el5PAE
Apache Version 2.2.3
MySQL Version 5.6.27-76.0
PERL Version 5.8.8
PHP Version 5.6.14
Ruby Version 1.9.3

CRM Version:

Version 7.7.5

Sugar Version 6.5.24 (Build 509)

I am unable to upgrade to PHP 7.X and I am forced to stay on 5.6.14 or downgrade to 5.3 or 5.2.

Per compatibility matrix I must be on 5.3 or higher. Just to rule it out I went to 5.2 and I received the following:

Warning: Unexpected character in input: ‘’ (ASCII=92) state=1 in /home/private/public_html/CRM/include/utils.php on line 1623

Parse error: syntax error, unexpected T_FUNCTION in /home/private/public_html/CRM/include/utils.php on line 4381

This version essentially causes SuiteCRM to not work and was forced to go to 5.3 or higher per matrix/requirements.

If I go to 5.3 I get the original error:

Fatal error: Call to undefined function mime_content_type() in /home/private/public_html/CRM/download.php on line 174

If I go back to 5.6.14 then I am still stuck with that issue. Any ideas on how I can enable this extension to fix the issue or any other means to get this to work?

Thanks in advance

You can make your own, then include it into the pages causing the errors. I’m not sure, but this one might work.

<?php
if(!function_exists('mime_content_type')) {

    function mime_content_type($filename) {

        $mime_types = array(

            'txt' => 'text/plain',
            'htm' => 'text/html',
            'html' => 'text/html',
            'php' => 'text/html',
            'css' => 'text/css',
            'js' => 'application/javascript',
            'json' => 'application/json',
            'xml' => 'application/xml',
            'swf' => 'application/x-shockwave-flash',
            'flv' => 'video/x-flv',

            // images
            'png' => 'image/png',
            'jpe' => 'image/jpeg',
            'jpeg' => 'image/jpeg',
            'jpg' => 'image/jpeg',
            'gif' => 'image/gif',
            'bmp' => 'image/bmp',
            'ico' => 'image/vnd.microsoft.icon',
            'tiff' => 'image/tiff',
            'tif' => 'image/tiff',
            'svg' => 'image/svg+xml',
            'svgz' => 'image/svg+xml',

            // archives
            'zip' => 'application/zip',
            'rar' => 'application/x-rar-compressed',
            'exe' => 'application/x-msdownload',
            'msi' => 'application/x-msdownload',
            'cab' => 'application/vnd.ms-cab-compressed',

            // audio/video
            'mp3' => 'audio/mpeg',
            'qt' => 'video/quicktime',
            'mov' => 'video/quicktime',

            // adobe
            'pdf' => 'application/pdf',
            'psd' => 'image/vnd.adobe.photoshop',
            'ai' => 'application/postscript',
            'eps' => 'application/postscript',
            'ps' => 'application/postscript',

            // ms office
            'doc' => 'application/msword',
            'rtf' => 'application/rtf',
            'xls' => 'application/vnd.ms-excel',
            'ppt' => 'application/vnd.ms-powerpoint',

            // open office
            'odt' => 'application/vnd.oasis.opendocument.text',
            'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
        );

        $ext = strtolower(array_pop(explode('.',$filename)));
        if (array_key_exists($ext, $mime_types)) {
            return $mime_types[$ext];
        }
        elseif (function_exists('finfo_open')) {
            $finfo = finfo_open(FILEINFO_MIME);
            $mimetype = finfo_file($finfo, $filename);
            finfo_close($finfo);
            return $mimetype;
        }
        else {
            return 'application/octet-stream';
        }
    }
}
?>

This isn’t the original solution I found, but many people across the WWW have been talking about how to basically replace this function in versions of PHP that don’t include it. If you don’t like the code above, or it doesn’t work, some google searching will help… no need to reference SuiteCRM in that searching.

sieberta

1 Like

Hello & thank you for the response Sieberta

“include it into the pages causing errors”? So I need to make a php.ini per page within CRM? Or modify the single php.ini within the root of my public_html folder?

Do you also recommend I stick with PHP 5.3 or 5.6?

My hosting provider is unable to help me any further so I am limited as to what I can do on the servers end.

Ok, so I’m not that great at upgrade-safe modifications to SuiteCRM…

You would create a file called mime_content_type.php and paste the contents I pasted below into it. I would also add some notes to remind yourself 3 years from now that you put that in (it wasn’t in the base install, why you put it in, and when it can be removed).

You would save that in \path\to\suitecrm\custom\include\

Then in /home/private/public_html/CRM/download.php (toward the top) you would put in the following…

// Function to replace depreciated mime_content_type(), can be removed after upgrade to PHP 7.X or above
include_once('custom\include\mime_content_type.php');

You should probably then set the permissions to your mime_content_type.php file to 755 and chown it as you did your entire installation.

Then do a quick repair & rebuild and test.

I don’t really have a preference on which PHP version you use, as long as it is in the SuiteCRM compatibility matrix.

sieberta

1 Like

Thank you for the response Sieberta

I have followed your instructions but I am now receiving this:

Warning: include_once(custom\include\mime_content_type.php) [function.include-once]: failed to open stream: No such file or directory in /home/private/public_html/CRM/download.php on line 42

Warning: include_once() [function.include]: Failed opening ‘custom\include\mime_content_type.php’ for inclusion (include_path=’/home/private/public_html/CRM:/home/private/public_html/CRM/include/HTMLPurifier/standalone:/home/private/public_html/CRM/include/…:.:’) in /home/private/public_html/CRM/download.php on line 42

Fatal error: Call to undefined function mime_content_type() in /home/private/public_html/CRM/download.php on line 176

I did change permissions, did a repair/rebuild, so it is failing to read/find download.php line or just doesn’t see the mime_content_type.php file?

Based on the error, it looks like you might be missing the tick ’ marks ’ around the path in this line?

include_once('custom\include\mime_content_type.php');

It is also possible/likely, that those should’ve been forward slashes / instead of back slashes ?

I apologize, but I’m offline until Monday! If getting the tick marks ’ in there and the slashes in the right direction doesn’t fix it, perhaps someone can pickup where I left off?

Also, this portion is just basic PHP (not SuiteCRM) so if you google something like “php include a file” you would probably find what we’re doing wrong.

Sorry we didn’t get it on the first stab!
sieberta

Ha! It was the backslashes! I too had a feeling about that. Tried it out and it works! Thank you very much Sieberta, in my book we (actually you) got it down on the first attempt.

Great Job Sieberta! Thank you once again and have a great weekend.

I don’t get errors when I attempt to download uploaded files attached to records.

When I click on the file, I am taken to a new window and then blank.

Any advice shall be highly appreciated.

Please check your server error logs.

sieberta