It seems clear to me by now that there will not be an easy solution to this problem. This means that the version of PHP might as well not have been built with the -with-mime-magic option at all. However, this file is not able to be read by my user. I found that my Hostgator server’s PHP is set up to use the /usr/local/apache/conf/magic file to do it’s MIME magic. The failure was worse than this, it simply returned an empty string to every single request. When I say “failed”, I don’t mean that the program crashed with an error. Every single test failed to produce a MIME type. I tested file after file ranging from simple text files, to HTML documents, to a variety of image types. ![]() I did some more testing on my Hostgator server and was disappointed to find that the mime_content_type function exists yet is completely worthless. Like my CentOS server, my Hostgator server does not have the Fileinfo PECL package and does not have PHP 5.3, so the finfo_* functions are no go. I ran a test, and the mime_content_type function did indeed exist. ![]() Unlike my dedicated server, this server’s PHP build was built with the -with-mime-magic option. On my Hostgator shared server, I have access to PHP 5.2.8. In addition to this, since the version is just before 5.3 and I haven’t installed the Fileinfo PECL package, my dedicated server does not have access to either of the official PHP solutions without installing additional software. The PHP build on this server was not built with the -with-mime-magic option, so it doesn’t have access to the mime_content_type function at all. On my CentOS 5.2 dedicated server, I have PHP 5.2.6. These problems led to interesting results when I tested it on my CentOS dedicated and Hostgator servers. This magic file may or may not exist/may or may not be readable. The function also relies upon the mime_magic.magicfile ini configuration to tell it where to find the magic file used to detect the MIME type of the file. In order to use the function the PHP on your system must have been built with the -with-mime-magic option. In addition to the deprecated issue, the mime_content_type function is laced with problems. Relying on a deprecated function has numerous problems: it may throw warnings if used on versions of PHP that know the function is deprecated, most likely won’t receive any updates in the future, and could possibly be removed from future versions of PHP. However, PHP has marked this function as deprecated due to the PECL Fileinfo package. I then found the mime_content_type function. I’m working toward a solution that doesn’t require the installation of any additional software, and so far I’ve only seen solutions that require this. Installing this package allows versions prior to 5.3.0 to use the finfo_* functions via PECL. ![]() Turns out that the Jelly and Custard post points to another post, Installing PECL Modules, where instructions are given for installing the Fileinfo PECL Package. Fortunately, my version of PHP was just before this so that I could actually catch the error. I pulled up the PHP doc on the finfo_open function and was very surprised to see that the function is a PHP 5.3.0+ function. Since I have PHP 5.2.6 running on my dev server, I was very confused since the post said that this was a “PHP 4.x” solution. I quickly tried it out on my server, and it failed instantly with the following error: PHP Fatal error: Call to undefined function finfo_open() in. The “Mime Types in PHP 4.x” seemed to be exactly what I wanted. I found a very helpful PHP, Mime Types and Fileinfo post on Jelly and Custard. Unfortunately, things were not as simple as this. I thought this would be a simple matter of finding a PHP function that does this. #Use php 5.2 hosgator softwareNot only did I need to create a solution that worked, I also needed the solution to be compatible with PHP 4/5 and not require any additional software to be installed on the host. I’m working on a project where I needed to generate a MIME type given a file name.
0 Comments
Leave a Reply. |
AuthorShendy ArchivesCategories |