Detecting a mime type fails in php

前端 未结 2 614
鱼传尺愫
鱼传尺愫 2021-01-19 23:59

I have the following PHP code that shows the mime type of an uploaded file.



        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-20 01:01

    I don't have a Unix box here to inspect a real "magic" file (the signatures database used to guess mime types) but a quick Google search revealed this:

    # $File: fortran,v 1.6 2009/09/19 16:28:09 christos Exp $
    # FORTRAN source
    0       regex/100       \^[Cc][\ \t]    FORTRAN program
    !:mime  text/x-fortran
    

    Apparently, it scans the start of the file looking for lines that begin with a single C letter plus spaces, which seem to be a Fortran style comment. Thus the false positive:

    somecolumn;
    C F;
    

提交回复
热议问题