Table of Contents
File Header文件头,通过检查文件头来判断文件类型
Home php教程 php手册 php 读取文件头部两个字节 判断文件的实际类型

php 读取文件头部两个字节 判断文件的实际类型

Jun 06, 2016 pm 07:45 PM
php judgment head byte actual document type read

function checkFileType($fileName){ $file = fopen($fileName, rb); $bin = fread($file, 2); //只读2字节 fclose($file); $strInfo = @unpack(C2chars, $bin);// C为无符号整数,网上搜到的都是c,为有符号整数,这样会产生负数判断不正常 $typeCode = int

 

 

File Header文件头,通过检查文件头来判断文件类型

由这些文件头即使文件后缀被乱改也可以通过查看二进制文件查出文件的匹配格式,当然这就是一些播放器识别文件的方法
1、从Ultra-edit-32中提取出来的

JPEG (jpg),文件头:FFD8FF
PNG (png),文件头:89504E47
GIF (gif),文件头:47494638
TIFF (tif),文件头:49492A00
Windows Bitmap (bmp),文件头:424D
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

二、从winhex中取出的文件头列表
File                             Type                          ExtensionsHeader
JPEG                             jpg;jpeg                      0xFFD8FF
PNG                              png                           0x89504E470D0A1A0A
GIF                              gif                           GIF8
TIFF                             tif;tiff                      0x49492A00
TIFF                             tif;tiff                      0x4D4D002A
Bit   map                         bmp                           BM
AOL ART                          art                           0x4A47040E000000
AOL ART                          art                           0x4A47030E000000
PC Paintbrush                    pcx                           0x0A050108
Graphics Metafile                wmf                           0xD7CDC69A
Graphics Metafile                wmf                           0x01000900
Graphics Metafile                wmf                           0x02000900
Enhanced Metafile                emf                           0x0100000058000000
Corel Draw                       cdr                           CDR
CAD                              dwg                           0x41433130
Adobe Photoshop                  psd                           8BPS
Rich Text Format                 rtf                           rtf
XML                              xml                              
HTML                 html;htm;php;php3;php4;phtml;shtml         type
Email                            eml                            Delivery-date:
Outlook Express                  dbx                            0xCFAD12FE
Outlookpst!BDN
MS Office/OLE2     doc;xls;dot;ppt;xla;ppa;pps;pot;msi;sdw;db   0xD0CF11E0A1B11AE1
MS Access                 mdb;mda;mde;mdt                       Standard J
WordPerfect                      wpd                           0xFF575043
OpenOffice Writer                sxw                           writer
OpenOffice Calc                  sxc                           calc
OpenOffice Math                  sxm                           math
OpenOffice Impress               sxi                           impress
OpenOffice Draw                  sxd                           draw
Adobe FrameMaker                 fm                             PostScript                       eps.or.ps;ps;eps              %!PS-Adobe
Adobe Acrobat                    pdf                           %PDF-1.
Quicken                          qdf                           0xAC9EBD8F
QuickBooks Backup                qbb                           0x458600000600
Sage                             sly.or.srt.or.slt;sly;srt;slt      0x53520100
Sage Backup                      1                                  SAGEBACKUP
Lotus WordPro v9                 lwp                           0x576F726450726F
Lotus 123 v9                     123                           0x00001A00051004
Lotus 123 v5                     wk4                           0x00001A0002100400
Lotus 123 v3                     wk3                           0x00001A0000100400
Lotus 123 v1                     wk1                            0x2000604060
Windows Password                 pwl                            0xE3828596
ZIP Archive                      zip;jar                        0x504B0304
ZIP Archive (outdated)           zip                            0x504B3030
RAR Archive                      rar                            Rar!
GZ Archive                       gz;tgz                         0x1F8B08
BZIP Archive                     bz2                            BZh
ARJ Archive                      arj                            0x60EA
7-ZIP Archive                   7z                             7z集'
Wave                             wav                            WAVE
AVI                              avi                            AVI
Real Audio                       ram;ra                         .ra?0
Real Media                       rm                             .RMF
MPEG                             mpg;mpeg                       0x000001BA
MPEG                             mpg;mpeg                       0x000001B3
Quicktime                        mov                            moov
Windows Media                    asf                            0x3026B2758E66CF11
MIDI                             mid                            MThd
Win32 Executable                 exe;dll;drv;vxd;sys;ocx;vbx    MZ
Win16 Executable                 exe;dll;drv;vxd;sys;ocx;vbx    MZ
ELF Executable                   elf;;                          0x7F454C4601010100

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

See all articles