站长博客
站长博客随手笔记
Toggle navigation
站长博客
Home
MacOS
Database
Linux
PHP
Git
Golang
About Me
Archives
Tags
二进制文件类型判断(无后缀情况)
2018-11-23 00:03:56
211
0
1
admin
```php $image = file_get_contents($url); echo check_image_type($image); function check_image_type($image) { $bits = array( 'JPEG' => "\xFF\xD8\xFF", 'GIF' => "GIF", 'PNG' => "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a", 'BMP' => 'BM', ); foreach ($bits as $type => $bit) { if (substr($image, 0, strlen($bit)) === $bit) { return $type; } } return 'UNKNOWN IMAGE TYPE'; } ``` 如果有些文件,比如是媒体文件,因格式太多,如果没有后缀名的话,在WIN下面是很难知道他是什么类型的,只有用播放器去放才知道, 整理了一些常用文件的头部编码, 这些头部编码可以用UltraEdit或是winhex来能过二进制方式打开文件来查看 从Ultraedit查看的头部编码 ``` JPEG (jpg),文件头:FFD8FF PNG (png),文件头:89504E47 GIF (gif),文件头:47494638 TIFF (tif),文件头:49492A00 Windows Bitmap (bmp),文件头:424D Execute File(.exe .dll .drv .vxd .sys .ocx .vbx) 文件头:4D5A900003 CAD (dwg),文件头:41433130 Adobe Photoshop (psd),文件头:38425053 Rich Text Format (rtf),文件头:7B5C727466 XML (xml),文件头:3C3F786D6C HTML (html),文件头:68746D6C3E Email [thorough only] (eml),文件头:44656C69766572792D646174653A Outlook Express (dbx),文件头:CFAD12FEC5FD746F Outlook (pst),文件头:2142444E MS Word/Excel (xls.or.doc),文件头:D0CF11E0 MS Access (mdb),文件头:5374616E64617264204A WordPerfect (wpd),文件头:FF575043 Postscript (eps.or.ps),文件头:252150532D41646F6265 Adobe Acrobat (pdf),文件头:255044462D312E Quicken (qdf),文件头:AC9EBD8F Windows Password (pwl),文件头:E3828596 ZIP Archive (zip),文件头:504B0304 RAR Archive (rar),文件头:52617221 Wave (wav),文件头:57415645 AVI (avi),文件头:41564920 Real Audio (ram),文件头:2E7261FD Real Media (rm),文件头:2E524D46 MPEG (mpg),文件头:000001BA MPEG (mpg),文件头:000001B3 Quicktime (mov),文件头:6D6F6F76 Windows Media (asf),文件头:3026B2758E66CF11 MIDI (mid),文件头:4D546864 ```
Prev:
MySQL 命令行下创建用户和授权
Next:
Linux系统里搜索文件内容
0
likes
211
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Table of content