mime_content_type is not working ..

i have in my php.ini as:

[mime_magic]
mime_magic.debug = On
mime_magic.magicfile = "C:\Program Files\xampp\php\extras\magic.mime"

Recommended Answers

All 19 Replies

Hi naju, What is the error message you are recieving and what version of php are you using, and are you using it on windows or linux?

ya its on windows
php 5.1.4
with xampp

the above mime_magic has been configure to all the php.ini in apache, php4 and php folder itself.

now it is showing an warning as
mime_magic not initialized in the line where it is called

try removing the .mime extension from this line:

mime_magic.magicfile = "C:\Program Files\xampp\php\extras\magic.mime"

so it looks like this:

mime_magic.magicfile = "C:\Program Files\xampp\php\extras\magic"

I am not sure whether this is the problem, but I have never seen the mime_magic.magicfile in the php.ini set with the .mime extension and it sounds like the magic_mime extension is not obeying.

Give this a go and let me know how it goes:)

same warning
mime_magic not initialized

Have you uncommented this module in your httpd.conf file:?

mod_mime_magic.so

it was not.
but now .. i have uncommented that ...
restarted my apache ...

again same warning
mime_magic not initialized

Ok , put the .mime extension back onto the path to the magicfile and also set this line:

mime_magic.debug = On

to:

mime_magic.debug = 0

I just done some research and read that the .mime extension must be added for win32 users and also that the mime_magic.debug only takes a boolean value (not sure if this is true, no harm in trying).

If this works then you can set the mime_magic.debug to 1 or true.

Try these steps and let me know, I'll do more research on this subject:)

P.S Keep the mod mentioned in earlier post uncommented. also restart apache after configering the php.ini file:)

Yeah coool

seems the initialization has been done, gr8.
no warning

but now the function is not returning any value
which does on my web-server(linux)

echo mime_content_type("index.php");

Ok now that it is getting initialized that is great. Try changing this line:

mime_magic.debug = 0

back to:

mime_magic.debug = On

I done more research and it can be set like this.

Try it now, everything should work:)

Warning
mime_magic not initialized
again appears

ummm.. undo the last change then and set it back to 0.

check and see if this line is uncommented in your httpd.conf file:

LoadModule mime_module modules/mod_mime.so

back to the same old warning

mime_magic not initialized

Ok lets do a test to see if maybe you are returning a invalid value. Create this one line script:

<?php echo mime_content_type('a'); ?>

Name it mime.php

Next put it in your root directory, and then open this file in your browser. The message you should see is:

'a' is a text file

If this is the message let me now:)

I very much appreciate your effort
but still not coming good days to me

the output is

Warning: mime_content_type() [http://www.php.net/mime_magic]: mime_magic not initialized in C:\Program Files\xampp\htdocs\generic05\mime.php on line 1

It's no problem, have you checked to see if maybe there is a later version of the magic.mime your using, I was reading somewhere once that in windows 32 that there was a certain version that didn't work, I may be off base with this but it might be worth researching. I'll do some researching for you as well as this may be good for both of us, as currently I haven't used mime_content_type on windows yet and would be good to know how.

Wait a tick, can you please post me the code for mime.php. I just clicked on that link you provided up the top and noticed something unusual. Just the first ten lines of it will be enough, only if you can:)

which one
are you talking about http://www.php.net/mime_magic

ok here it goes:
----------------------------------

Mimetype Functions
Introduction
Warning

This extension has been deprecated as the PECL extension Fileinfo provides the same functionality (and more) in a much cleaner way.

The functions in this module try to guess the content type and encoding of a file by looking for certain magic byte sequences at specific positions within the file. While this is not a bullet proof approach the heuristics used do a very good job.

This extension is derived from Apache mod_mime_magic, which is itself based on the file command maintained by Ian F. Darwin. See the source code for further historic and copyright information.
Requirements

No external libraries are needed to build this extension.
Installation

You must compile PHP with the configure switch --with-mime-magic to get support for mime-type functions. The extension needs a copy of the simplified magic file that is distributed with the Apache httpd.

Note: The configure option has been changed from --enable-mime-magic to --with-mime-magic since PHP 4.3.2

Note: This extension is not capable of handling the fully decorated magic file that generally comes with standard Linux distro's and is supposed to be used with recent versions of file command.

Thats the one I read, have you tried this? I haven't used mime on windows, so this is new to me too:)

OK Thanks for the follow up till here

here is the conclusion for the post:
mime_type is not supported for windows

The Next episode of this post will be along with the news "mime_type" is also supported on windows

thanks everybody for visiting the post

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.