異なる結果を返す「file --mime-type」および「mimetype」コマンド


9

こんにちは私はPHPが「msword」ファイルタイプを返す理由を解明しようとしています。以下の結果からわかるように、それらは異なる結果を返します。なぜ誰かが説明できますか?

root@dev:~# file --mime-type 1.xls
1.xls: application/msword
root@dev:~# mimetype 1.xls
1.xls: application/vnd.ms-excel

また、問題のファイルがWindowsサーバーで「msword」を返していることにも注意してください。PHPExcelを使用して生成されました。

ご協力いただきありがとうございます。

回答:


7

fileから結果を取得します/etc/mime.types

そこから:

application / mathematica-old
application / ms-tnef
application / msaccess mdb
application / msword doc dot
application / news-message-id
アプリケーション/ニュース送信
application / ocsp-request
application / ocsp-response

mimetypeはそれを取得します...

ENVIRONMENT

   XDG_DATA_HOME
   XDG_DATA_DIRS
       These variables can list base directories to search for data files.
       The shared mime-info will be expected in the "mime" sub directory
       of one of these directories. If these are not set, there will be
       searched for the following directories:

               $HOME/.local/share/mime
               /usr/local/share/mime
               /usr/share/mime

       See also the "XDG Base Directory Specification"
       http://freedesktop.org/Standards/basedir-spec
       <http://freedesktop.org/Standards/basedir-spec>

注目に値するのは、mimetypeのmanページのこの部分です。

スイッチに名前を付けるために、可能であればfile(1)バージョン4.02のマンページに従いました。IEEE Std 1003.1-2001(POSIX)の「ユーティリティ」の章にある仕様とは完全に異なるようです。

したがって/etc/mime.typesvnd.ms-excelより正確なので、ファイルに対するバグと呼ぶかもしれません。


WindowsとLinuxの両方で問題が解決しないようです。説明ありがとう。
scampbell 2013

ええ、それについて考えています... mimetypeはおそらくデスクトップのみなので、サーバーを扱うときはファイルを使用します。
Rinzwind 2013

12.04を使用していますが、編集/etc/mime.typesしてもの結果には影響しませんfile
congusbongus

5

.debパッケージ用の2つのツールには同様の違いがあります。

これは、表示され、そのファイルが使用する/etc/mime.typesmimetype、よりはるかに複雑なドロドロ使用していますXDG_DATA_DIRS(からのman mimetypes):

ENVIRONMENT
       XDG_DATA_HOME
       XDG_DATA_DIRS
           These variables can list base directories to search for data files. The shared mime-info will be expected in the "mime" sub directory of one of these directories. If these are not set,
           there will be searched for the following directories:

                   $HOME/.local/share/mime
                   /usr/local/share/mime
                   /usr/share/mime

           See also the "XDG Base Directory Specification" http://freedesktop.org/Standards/basedir-spec <http://freedesktop.org/Standards/basedir-spec>

FILES
       The base dir for all data files is determined by two environment variables, see "ENVIRONMENT".

       BASE/mime/packages/SOURCE.xml
           All other files are compiled from these source files. To re-compile them use update-mime-database(1).

       BASE/mime/globs
           Compiled information about globs.

       BASE/mime/magic
           Compiled information about magic numbers.

       BASE/mime/MEDIA/SUBTYPE.xml
           Descriptions of a mimetype in multiple languages, used for the "--describe" switch.

WindowsとLinuxの両方で問題が解決しないようです。説明ありがとう。謝罪2をアンサーとしてマークすることはできません。どちらもしっかりしていた。
scampbell 2013

1

見つけるのに少し時間がかかりましたが、debianにmimetypeをインストールすることができました。

sudo apt-get install libfile-mimeinfo-perl

application/vnd.ms-excelでは.xlsではなく.xls を取得していapplication/mswordます。


0

あなたはPHPでそれをしていると述べました。MIMEタイプのファイルを取得するときに、このような違いが発生しました。それらは異なります。PHPでそれを正しく行うには、finfoを使用する必要があります

$finfo = new finfo();
$mime = $finfo->file($path_to_file, FILEINFO_MIME);

おかげで私はすでにこの機能を使用しています。不正な形式を返します。これが私がテストしていた理由です。
scampbell 2013

それはどのフォーマットを返しますか?
2013年

元の質問を参照
scampbell 2013年

そこでは、finfoを使用したことについては触れませんでした。mswordを返しますか?
2013年
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.