是否有可用于PHP的文件描述脚本的文件扩展名?

| 我正在寻找的东西将采用为其赋予的任何文件扩展名,并返回对该扩展名的描述。 例如 :
$extension = \'PNG\';
$description = ext_description($extension);

echo $description // Outputs \'Portable Network Graphic\'
要么
 $extension = \'DOC\';
 $description = ext_description($extension);

 echo $description // Outputs \'Microsoft Office Word Document\'
我已经搜索过Google,但没有发现任何问题。如果有人知道是否存在这样的脚本,那将节省大量时间。 提前致谢。     
已邀请:
        是的,有一个,是getID3库,在fileinfo库中有PHP版本。 由于每个人的描述都不一样,因此您可以创建一个对数组数据起作用的简单查找函数。您只需要将文件类型添加到数组中就可以了:
function ext_description($extension) {
    static extensions = array(
        \'png\' => \'Portable Network Graphic\',
        \'doc\' => \'Microsoft Office Word Document\'
    );
    $extension = strtolower($extension);
    return isset($extensions[$extension])
        ? $extensions[$extension]
        : sprintf(\'Unknown File (%s)\', $extension)
        ;
}
    
        它不存在,但是您可以创建一个。
function ext_description($extension) {
    switch ($extension) {
    case \"png\":
        return \"Portable Network Graphic\";
    case \"doc\":
        return \"Microsoft Office Word Document\";
    default:
        return \"Unknow extention\";
}
您可以在此处找到所有现有扩展的完整列表:http://en.wikipedia.org/wiki/List_of_file_formats_(alphabetical)     
        不,在PHP中没有简单的方法可以做到这一点。最接近的替代方法是MIME类型,可以使用
finfo
mime_content_type
获得。 如果您在Windows上运行,则还可以使用
SHGetFileInfo
函数,该函数完全可以满足您的需求。   http://msdn.microsoft.com/zh-CN/library/bb762179(v=vs.85).aspx     
        如果有人需要,这就是我目前用于上述问题的内容。
/**
 * Takes a file extension and returns a readable file type.
 * 
 * @param string $ext
 * @return string
 * @example .doc returns Microsoft Word Document
 */
function file_extension_2_type($ext) {

    $files = json_decode(\'{\".doc\":\"Microsoft Word Document\",\".docx\":\"Microsoft Word Open XML Document\",\".log\":\"Log File\",\".msg\":\"Outlook Mail Message\",\".pages\":\"Pages Document\",\".rtf\":\"Rich Text Format File\",\".txt\":\"Plain Text File\",\".wpd\":\"WordPerfect Document\",\".wps\":\"Microsoft Works Word Processor Document\",\".csv\":\"Comma Separated Values File\",\".dat\":\"Data File\",\".efx\":\"eFax Document\",\".gbr\":\"Gerber File\",\".key\":\"Keynote Presentation\",\".pps\":\"PowerPoint Slide Show\",\".ppt\":\"PowerPoint Presentation\",\".pptx\":\"PowerPoint Open XML Presentation\",\".sdf\":\"Standard Data File\",\".vcf\":\"vCard File\",\".xml\":\"XML File\",\".aif\":\"Audio Interchange File Format\",\".iff\":\"Interchange File Format\",\".m3u\":\"Media Playlist File\",\".m4a\":\"MPEG-4 Audio File\",\".mid\":\"MIDI File\",\".mp3\":\"MP3 Audio File\",\".mpa\":\"MPEG-2 Audio File\",\".wav\":\"WAVE Audio File\",\".wma\":\"Windows Media Audio File\",\".3g2\":\"3GPP2 Multimedia File\",\".3gp\":\"3GPP Multimedia File\",\".asf\":\"Advanced Systems Format File\",\".asx\":\"Microsoft ASF Redirector File\",\".avi\":\"Audio Video Interleave File\",\".flv\":\"Flash Video File\",\".mov\":\"Apple QuickTime Movie\",\".mp4\":\"MPEG-4 Video File\",\".mpg\":\"MPEG Video File\",\".swf\":\"Shockwave Flash Movie\",\".vob\":\"DVD Video Object File\",\".wmv\":\"Windows Media Video File\",\".3dm\":\"Rhino 3D Model\",\".max\":\"3ds Max Scene File\",\".bmp\":\"Bitmap Image File\",\".gif\":\"Graphical Interchange Format File\",\".jpg\":\"JPEG Image File\",\".png\":\"Portable Network Graphic\",\".psd\":\"Adobe Photoshop Document\",\".pspimage\":\"PaintShop Pro Image\",\".thm\":\"Thumbnail Image File\",\".tif\":\"Tagged Image File\",\".yuv\":\"YUV Encoded Image File\",\".ai\":\"Adobe Illustrator File\",\".drw\":\"Drawing File\",\".eps\":\"Encapsulated PostScript File\",\".ps\":\"PostScript File\",\".svg\":\"Scalable Vector Graphics File\",\".indd\":\"Adobe InDesign Document\",\".pct\":\"Picture File\",\".pdf\":\"Portable Document Format File\",\".qxd\":\"QuarkXPress Document\",\".qxp\":\"QuarkXPress Project File\",\".rels\":\"Open Office XML Relationships File\",\".xlr\":\"Works Spreadsheet\",\".xls\":\"Excel Spreadsheet\",\".xlsx\":\"Microsoft Excel Open XML Spreadsheet\",\".accdb\":\"Access 2007 Database File\",\".db\":\"Database File\",\".dbf\":\"Database File\",\".mdb\":\"Microsoft Access Database\",\".pdb\":\"Program Database\",\".sql\":\"Structured Query Language Data\",\".app\":\"Mac OS X Application\",\".bat\":\"DOS Batch File\",\".cgi\":\"Common Gateway Interface Script\",\".com\":\"DOS Command File\",\".exe\":\"Windows Executable File\",\".gadget\":\"Windows Gadget\",\".jar\":\"Java Archive File\",\".pif\":\"Program Information File\",\".vb\":\"VBScript File\",\".wsf\":\"Windows Script File\",\".gam\":\"Saved Game File\",\".nes\":\"Nintendo (NES) ROM File\",\".rom\":\"N64 Game ROM File\",\".sav\":\"Saved Game\",\".dwg\":\"AutoCAD Drawing Database File\",\".dxf\":\"Drawing Exchange Format File\",\".gpx\":\"GPS Exchange File\",\".kml\":\"Keyhole Markup Language File\",\".asp\":\"Active Server Page\",\".cer\":\"Internet Security Certificate\",\".csr\":\"Certificate Signing Request File\",\".css\":\"Cascading Style Sheet\",\".htm\":\"Hypertext Markup Language File\",\".html\":\"Hypertext Markup Language File\",\".js\":\"JavaScript File\",\".jsp\":\"Java Server Page\",\".php\":\"Hypertext Preprocessor File\",\".rss\":\"Rich Site Summary\",\".xhtml\":\"Extensible Hypertext Markup Language File\",\".8bi\":\"Photoshop Plug-in\",\".plugin\":\"Mac OS X Plug-in\",\".xll\":\"Excel Add-In File\",\".fnt\":\"Windows Font File\",\".fon\":\"Generic Font File\",\".otf\":\"OpenType Font\",\".ttf\":\"TrueType Font\",\".cab\":\"Windows Cabinet File\",\".cpl\":\"Windows Control Panel Item\",\".cur\":\"Windows Cursor\",\".dll\":\"Dynamic Link Library\",\".dmp\":\"Windows Memory Dump\",\".drv\":\"Device Driver\",\".lnk\":\"File Shortcut\",\".sys\":\"Windows System File\",\".cfg\":\"Configuration File\",\".ini\":\"Windows Initialization File\",\".keychain\":\"Mac OS X Keychain File\",\".prf\":\"Outlook Profile File\",\".bin\":\"Macbinary Encoded File\",\".hqx\":\"BinHex 4.0 Encoded File\",\".mim\":\"Multi-Purpose Internet Mail Message File\",\".uue\":\"Uuencoded File\",\".7z\":\"7-Zip Compressed File\",\".deb\":\"Debian Software Package\",\".gz\":\"Gnu Zipped Archive\",\".pkg\":\"Mac OS X Installer Package\",\".rar\":\"WinRAR Compressed Archive\",\".rpm\":\"Red Hat Package Manager File\",\".sit\":\"Stuffit Archive\",\".sitx\":\"Stuffit X Archive\",\".tar.gz\":\"Tarball File\",\".zip\":\"Zipped File\",\".zipx\":\"Extended Zip File\",\".dmg\":\"Mac OS X Disk Image\",\".iso\":\"Disc Image File\",\".toast\":\"Toast Disc Image\",\".vcd\":\"Virtual CD\",\".c\":\"C\\/C++ Source Code File\",\".class\":\"Java Class File\",\".cpp\":\"C++ Source Code File\",\".cs\":\"Visual C# Source Code File\",\".dtd\":\"Document Type Definition File\",\".fla\":\"Adobe Flash Animation\",\".java\":\"Java Source Code File\",\".m\":\"Objective-C Implementation File\",\".pl\":\"Perl Script\",\".py\":\"Python Script\",\".bak\":\"Backup File\",\".gho\":\"Norton Ghost Backup File\",\".ori\":\"Original File\",\".tmp\":\"Temporary File\",\".dbx\":\"Outlook Express E-mail Folder\",\".msi\":\"Windows Installer Package\",\".part\":\"Partially Downloaded File\",\".torrent\":\"BitTorrent File\"}\', true);


    if (isset($files[\'.\' . strtolower($ext)]))
        return $files[\'.\' . strtolower($ext)] . \' (\' . strtoupper($ext) . \')\';


    return strtoupper($ext);
}
    
        您可以使用文件http://www.feedforall.com/mime-types.htm的MIME类型     

要回复问题请先登录注册