다른 결과를 반환하는 'file --mime-type'및 'mimetype'명령


9

안녕하세요, 왜 'excel'이어야 할 때 PHP가 'msword'파일 형식을 반환하는지 알아 내려고 노력 중이므로 'file'및 'mimetype'명령을 모두 사용하여 우분투 상자에서 테스트했습니다. 아래 결과에서 볼 수 있듯이 다른 결과를 반환합니다. 아무도 이유를 설명 할 수 있습니까?

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

또한 문제의 파일이 Windows Server에서 'msword'를 반환하고 있습니다. PHPExcel을 사용하여 생성되었습니다.

당신의 도움을 주셔서 감사합니다.

답변:


7

file에서 결과를 얻습니다 /etc/mime.types.

거기에서:

응용 프로그램 / 수학
응용 프로그램 / ms-tnef
응용 프로그램 / msaccess mdb
응용 프로그램 / msword doc dot
응용 프로그램 / 뉴스 메시지 ID
응용 프로그램 / 뉴스 전송
응용 프로그램 / ocsp- 요청
응용 프로그램 / 응답

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 매뉴얼 페이지에서이 부분을 주목할 가치가 있습니다.

명명 스위치의 경우 가능한 경우 file (1) 버전 4.02 맨 페이지를 따랐습니다. IEEE Std 1003.1-2001 (POSIX)의 '유틸리티'장에 나와있는 사양과 완전히 다른 것 같습니다.

더 정확하기 /etc/mime.types때문에 파일에 대한 버그라고 할 수 있습니다 vnd.ms-excel.


Windows와 Linux 모두에서 문제가 발생하는 것처럼 보입니다. 설명 주셔서 감사합니다.
scampbell

그래 그리고 그것에 대해 생각하고 ... mimetype은 아마도 데스크탑 일뿐이므로 서버를 다룰 ​​때 파일을 사용할 것입니다.
Rinzwind

12.04에 있는데 편집 /etc/mime.types결과가에 영향을 미치지 않는 것으로 보입니다 file.
congusbongus

5

.deb패키지 용 두 도구 간에는 유사한 차이점이 있습니다 .

그것은 나타납니다 그 파일의 용도 /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

1

그것을 찾는 데 시간이 걸렸지 만 데비안에서 mimetype을 설치할 수있었습니다.

sudo apt-get install libfile-mimeinfo-perl

이제 application/vnd.ms-excel대신 .xls를 얻 습니다 application/msword.


0

PHP에서하고 있다고 언급했습니다. MIME 유형의 파일을 가져올 때 이러한 차이점이 발생했습니다. 그들은 다릅니다. PHP에서 제대로하려면 finfo를 사용해야합니다

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

감사합니다. 이미이 기능을 사용하고 있습니다. 잘못된 형식을 반환합니다. 이것이 제가 테스트하는 이유입니다.
scampbell

어떤 형식을 반환합니까?
llt

원래 질문보기
scampbell

finfo를 사용했다고 언급하지 않았습니다. msword를 반환합니까?
llt
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.