Css mime type return as text / plain, not text / css

I use this code to get mime type from given file

$finfo = new \finfo(FILEINFO_MIME_TYPE); $mime = $finfo->buffer(file_get_contents($file)); 

If I give him a PHP file, then I get

 text/x-php 

but if I give it a CSS file, I get

 text/plain 

I tried to solve this problem to no avail, I have AddType in my Apache to allow CSS file types.

Anyone have any suggestions?

+6
source share
1 answer

You need to tell Apache to show files as text / css when their extension is .css . The only reasonable way for your server to distinguish between a stylesheet and any other type of text file is by file name.

You can do this by editing a configuration file like Apache MIME called mime.types (it lives in a different folder depending on your distribution, maybe try / etc / apache2) to make the following association:

 text/css css 

Alternatively, if you do not have administrator access, you can create a .htaccess file in your own root web server. Read more about both methods here.

Hope this helps!

After re-reading our question, perhaps I misunderstood you, and you have already taken the steps above?

If so, could you check that your OS reads mimetype like? There are suitable commands for checking mimetype, here :

Also, it seems like it would be pragmatic to add a follow-up check to see if the file extension ends with .css. Is there a reason why this will not work?

+5
source

Source: https://habr.com/ru/post/916824/


All Articles