PHP 基于文件头的文件类型验证类函数
程序员文章站
2022-03-30 22:16:40
我这里写了一个验证类,是通过文件头来判断文件格式.(也不是百分之百安全,如果用户伪造了文件头,也能通过验证) 复制代码 代码如下:
我这里写了一个验证类,是通过文件头来判断文件格式.(也不是百分之百安全,如果用户伪造了文件头,也能通过验证)
<?php
/**
* 检证文件类型类
*
* @author silver
*/
class filetypevalidation
{
// 文件类型,不同的头信息
private static $_fileformats = array(
'jp2' => '0000000c6a502020',<br/> '3gp' => '0000002066747970',
'3gp5' => '0000001866747970',
'm4a' => '00000020667479704d3441',
'ico' => '00000100',
'spl' => '00000100',
'vob' => '000001ba',
'cur' => '00000200',
'wb2' => '00000200',
'wk1' => '0000020006040600',
'wk3' => '00001a0000100400',
'wk4' => '00001a0002100400',
'wk5' => '00001a0002100400',
'123' => '00001a00051004',
'qxd' => '00004d4d585052',
'mdf' => '010f0000',
'tr1' => '0110',
'rgb' => '01da01010003',
'drw' => '07',
'dss' => '02647373',
'dat' => 'a90d000000000000',
'db3' => '03',
'qph' => '03000000',
'adx' => '80000020031204',
'db4' => '04',
'n' => 'fffe0000',
'a' => 'fffe0000',
'skf' => '07534b46',
'dtd' => '0764743264647464',
'db' => 'd0cf11e0a1b11ae1',
'pcx' => '0a050101',
'mp' => '0ced',
'doc' => 'd0cf11e0a1b11ae1',
'nri' => '0e4e65726f49534f',
'wks' => 'ff00020004040554',
'pf' => '1100000053434341',
'ntf' => '4e49544630',
'nsf' => '4e45534d1a01',
'arc' => '41724301',
'pak' => '5041434b',
'eth' => '1a350100',
'mkv' => '1a45dfa393428288',
'ws' => '1d7d',
'gz' => '1f8b08',
'tar.z' => '1fa0',
'ain' => '2112',
'lib' => '213c617263683e0a',
'msi' => 'd0cf11e0a1b11ae1',
'vmdk' => '4b444d',
'dsp' => '23204d6963726f73',
'amr' => '2321414d52',
'hdr' => '49536328',
'sav' => '24464c3240282329',
'eps' => 'c5d0d3c6',
'pdf' => '25504446',
'fdf' => '25504446',
'hqx' => '2854686973206669',
'log' => '2a2a2a2020496e73',
'ivr' => '2e524543',
'rm' => '2e524d46',
'rmvb' => '2e524d46',
'ra' => '2e7261fd00',
'au' => '646e732e',
'cat' => '30',
'evt' => '300000004c664c65',
'asf' => '3026b2758e66cf11',
'wma' => '3026b2758e66cf11',
'wmv' => '3026b2758e66cf11',
'wri' => 'be000000ab',
'7z' => '377abcaf271c',
'psd' => '38425053',
'sle' => '414376',
'asx' => '3c',
'xdr' => '3c',
'dci' => '3c21646f63747970',
'manifest' => '3c3f786d6c2076657273696f6e3d',
'xml' => '3c3f786d6c2076657273696f6e3d22312e30223f3e',
'msc' => 'd0cf11e0a1b11ae1',
'fm' => '3c4d616b65724669',
'mif' => '56657273696f6e20',
'gid' => '4c4e0200',
'hlp' => '4c4e0200',
'dwg' => '41433130',
'syw' => '414d594f',
'abi' => '414f4c494e444558',
'aby' => '414f4c4442',
'bag' => '414f4c2046656564',
'idx' => '5000000020000000',
'ind' => '414f4c494458',
'pfc' => '414f4c564d313030',
'org' => '414f4c564d313030',
'vcf' => '424547494e3a5643',
'bin' => '424c4932323351',
'bmp' => '424d',
'dib' => '424d',
'prc' => '424f4f4b4d4f4249',
'bz2' => '425a68',
'tar.bz2' => '425a68',
'tbz2' => '425a68',
'tb2' => '425a68',
'rtd' => '43232b44a4434da5',
'cbd' => '434246494c45',
'iso' => '4344303031',
'clb' => '434f4d2b',
'cpt' => '43505446494c45',
'cru' => '43525553482076',
'swf' => '465753',
'ctf' => '436174616c6f6720',
'dms' => '444d5321',
'adf' => '5245564e554d3a2c',
'dvr' => '445644',
'ifo' => '445644',
'cdr' => '52494646',
'vcd' => '454e545259564344',
'mdi' => '4550',
'e01' => '4c5646090d0aff00',
'evtx' => '456c6646696c6500',
'qbb' => '458600000600',
'cpe' => '464158434f564552',
'flv' => '464c56',
'aiff' => '464f524d00',
'eml' => '582d',
'gif' => '47494638',
'pat' => '47504154',
'gx2' => '475832',
'sh3' => '4848474231',
'tif' => '4d4d002b',
'tiff' => '4d4d002b',
'mp3' => '494433',
'koz' => '49443303000000',
'crw' => '49491a0000004845',
'cab' => '4d534346',
'lit' => '49544f4c49544c53',
'chi' => '49545346',
'chm' => '49545346',
'jar' => '5f27a889',
'jg' => '4a47040e000000',
'kgb' => '4b47425f61726368',
'shd' => '68490000',
'lnk' => '4c00000001140200',
'obj' => '80',
'pdb' => 'aced000573720012',
'mar' => '4d41723000',
'dmp' => '504147454455',
'hdmp' => '4d444d5093a7',
'mls' => '4d563243',
'mmf' => '4d4d4d440000',
'nvram' => '4d52564e',
'ppz' => '4d534346',
'snp' => '4d534346',
'tlb' => '4d53465402000100',
'dvf' => '4d535f564f494345',
'msv' => '4d535f564f494345',
'mid' => '4d546864',
'midi' => '4d546864',
'dsn' => '4d56',
'com' => 'eb',
'dll' => '4d5a',
'drv' => '4d5a',
'exe' => '4d5a',
'pif' => '4d5a',
'qts' => '4d5a',
'qtx' => '4d5a',
'sys' => 'ffffffff',
'acm' => '4d5a',
'ax' => '4d5a900003000000',
'cpl' => 'dcdc',
'fon' => '4d5a',
'ocx' => '4d5a',
'olb' => '4d5a',
'scr' => '4d5a',
'vbx' => '4d5a',
'vxd' => '4d5a',
'386' => '4d5a',
'api' => '4d5a900003000000',
'flt' => '76323030332e3130',
'zap' => '4d5a90000300000004000000ffff',
'sln' => '4d6963726f736f66742056697375616c',
'jnt' => '4e422a00',
'jtp' => '4e422a00',
'cod' => '4e616d653a20',
'dbf' => '4f504c4461746162',
'oga' => '4f67675300020000',
'ogg' => '4f67675300020000',
'ogv' => '4f67675300020000',
'ogx' => '4f67675300020000',
'dw4' => '4f7b',
'pgm' => '50350a',
'pax' => '504158',
'pgd' => '504750644d41494e',
'img' => 'eb3c902a',
'zip' => '504b0304140000',
'docx' => '504b030414000600',
'pptx' => '504b030414000600',
'xlsx' => '504b030414000600',
'kwd' => '504b0304',
'odt' => '504b0304',
'odp' => '504b0304',
'ott' => '504b0304',
'sxc' => '504b0304',
'sxd' => '504b0304',
'sxi' => '504b0304',
'sxw' => '504b0304',
'wmz' => '504b0304',
'xpi' => '504b0304',
'xps' => '504b0304',
'xpt' => '5850434f4d0a5479',
'grp' => '504d4343',
'qemu' => '514649',
'abd' => '5157205665722e20',
'qsd' => '5157205665722e20',
'reg' => 'fffe',
'sud' => '52454745444954',
'ani' => '52494646',
'cmx' => '52494646',
'ds4' => '52494646',
'4xm' => '52494646',
'avi' => '52494646',
'cda' => '52494646',
'qcp' => '52494646',
'rmi' => '52494646',
'wav' => '52494646',
'cap' => '58435000',
'rar' => '526172211a0700',
'ast' => '5343486c',
'shw' => '53484f57',
'cpi' => 'ff464f4e54',
'sit' => '5374756666497420',
'sdr' => '534d415254445257',
'cnv' => '53514c4f434f4e56',
'cal' => 'b5a2b0b3b3b0a5b5',
'info' => 'e310000100000000',
'uce' => '55434558',
'ufa' => '554641c6d2c1',
'pch' => '564350434830',
'ctl' => '56455253494f4e20',
'ws2' => '575332303030',
'lwp' => '576f726450726f',
'bdr' => '5854',
'zoo' => '5a4f4f20',
'ecf' => '5b47656e6572616c',
'vcw' => '5b4d535643',
'dun' => '5b50686f6e655d',
'sam' => '5b7665725d',
'cpx' => '5b57696e646f7773',
'cfg' => '5b666c7473696d2e',
'cas' => '5f434153455f',
'cbk' => '5f434153455f',
'arj' => '60ea',
'vhd' => '636f6e6563746978',
'csh' => '6375736800000002',
'p10' => '64000000',
'dex' => '6465780a30303900',
'dsw' => '64737766696c65',
'flac' => '664c614300000022',
'dbb' => '6c33336c',
'acd' => '72696666',
'ram' => '727473703a2f2f',
'dmg' => '78',
'lgc' => '7b0d0a6f20',
'lgd' => '7b0d0a6f20',
'pwi' => '7b5c707769',
'rtf' => '7b5c72746631',
'psp' => '7e424b00',
'wab' => '9ccbcb8d1375d211',
'wpf' => '81cdab',
'png' => '89504e470d0a1a0a',
'aw' => '8a0109000000e108',
'hap' => '91334846',
'skr' => '9501',
'gpg' => '99',
'pkr' => '9901',
'qdf' => 'ac9ebd8f0000',
'pwl' => 'e3828596',
'dcx' => 'b168de3a',
'tib' => 'b46e6844',
'acs' => 'c3abcdab',
'lbk' => 'c8007900',
'class' => 'cafebabe',
'dbx' => 'cfad12fe',
'dot' => 'd0cf11e0a1b11ae1',
'pps' => 'd0cf11e0a1b11ae1',
'ppt' => 'd0cf11e0a1b11ae1',
'xla' => 'd0cf11e0a1b11ae1',
'xls' => 'd0cf11e0a1b11ae1',
'wiz' => 'd0cf11e0a1b11ae1',
'ac_' => 'd0cf11e0a1b11ae1',
'adp' => 'd0cf11e0a1b11ae1',
'apr' => 'd0cf11e0a1b11ae1',
'mtw' => 'd0cf11e0a1b11ae1',
'opt' => 'd0cf11e0a1b11ae1',
'pub' => 'd0cf11e0a1b11ae1',
'rvt' => 'd0cf11e0a1b11ae1',
'sou' => 'd0cf11e0a1b11ae1',
'spo' => 'd0cf11e0a1b11ae1',
'vsd' => 'd0cf11e0a1b11ae1',
'wps' => 'd0cf11e0a1b11ae1',
'ftr' => 'd20a0000',
'arl' => 'd42a',
'aut' => 'd42a',
'wmf' => 'd7cdc69a',
'efx' => 'dcfe',
'one' => 'e4525c7b8cd8a74d',
'rpm' => 'edabeedb',
'gho' => 'feef',
'ghs' => 'feef',
'wp' => 'ff575043',
'wpd' => 'ff575043',
'wpg' => 'ff575043',
'wpp' => 'ff575043',
'wp5' => 'ff575043',
'wp6' => 'ff575043',
'jfif' => 'ffd8ff',
'jpe' => 'ffd8ff',
'jpeg' => 'ffd8ff',
'jpg' => 'ffd8ff',
'mof' => 'fffe23006c006900',
'ipa' => '504b03040a',
);
/**
* 检查文件类型
*
* @param string $filepath 文件路径
* @param string $fileext 文件扩展名
*
* @return boolean
*/
public static function validation($filepath, $fileext)
{
// 文件格式未知
if (!isset(self::$_fileformats[$fileext]))
{
return false;
}
$length = strlen(self::$_fileformats[$fileext]);
$bin = self::_readfile($filepath, $length);
$filehead = @unpack("h{$length}", $bin);
// 判断文件头
if (strtolower(self::$_fileformats[$fileext]) == $filehead[1])
{
return true;
}
return false;
}
/**
* 读取文件内容
*
* @param string $filepath 文件路径
* @param integer $size
*
* @return string
*/
private function _readfile($filepath, $size)
{
$file = fopen($filepath, "rb");
$bin = fread($file, $size);
fclose($file);
return $bin;
}
}
?>
调用
require './class_filetypevalidation.php';
// 文件路径
$filepath = "d:/test.png";
$x = filetypevalidation::validation($filepath, 'zip');
var_dump($x);
复制代码 代码如下:
<?php
/**
* 检证文件类型类
*
* @author silver
*/
class filetypevalidation
{
// 文件类型,不同的头信息
private static $_fileformats = array(
'jp2' => '0000000c6a502020',<br/> '3gp' => '0000002066747970',
'3gp5' => '0000001866747970',
'm4a' => '00000020667479704d3441',
'ico' => '00000100',
'spl' => '00000100',
'vob' => '000001ba',
'cur' => '00000200',
'wb2' => '00000200',
'wk1' => '0000020006040600',
'wk3' => '00001a0000100400',
'wk4' => '00001a0002100400',
'wk5' => '00001a0002100400',
'123' => '00001a00051004',
'qxd' => '00004d4d585052',
'mdf' => '010f0000',
'tr1' => '0110',
'rgb' => '01da01010003',
'drw' => '07',
'dss' => '02647373',
'dat' => 'a90d000000000000',
'db3' => '03',
'qph' => '03000000',
'adx' => '80000020031204',
'db4' => '04',
'n' => 'fffe0000',
'a' => 'fffe0000',
'skf' => '07534b46',
'dtd' => '0764743264647464',
'db' => 'd0cf11e0a1b11ae1',
'pcx' => '0a050101',
'mp' => '0ced',
'doc' => 'd0cf11e0a1b11ae1',
'nri' => '0e4e65726f49534f',
'wks' => 'ff00020004040554',
'pf' => '1100000053434341',
'ntf' => '4e49544630',
'nsf' => '4e45534d1a01',
'arc' => '41724301',
'pak' => '5041434b',
'eth' => '1a350100',
'mkv' => '1a45dfa393428288',
'ws' => '1d7d',
'gz' => '1f8b08',
'tar.z' => '1fa0',
'ain' => '2112',
'lib' => '213c617263683e0a',
'msi' => 'd0cf11e0a1b11ae1',
'vmdk' => '4b444d',
'dsp' => '23204d6963726f73',
'amr' => '2321414d52',
'hdr' => '49536328',
'sav' => '24464c3240282329',
'eps' => 'c5d0d3c6',
'pdf' => '25504446',
'fdf' => '25504446',
'hqx' => '2854686973206669',
'log' => '2a2a2a2020496e73',
'ivr' => '2e524543',
'rm' => '2e524d46',
'rmvb' => '2e524d46',
'ra' => '2e7261fd00',
'au' => '646e732e',
'cat' => '30',
'evt' => '300000004c664c65',
'asf' => '3026b2758e66cf11',
'wma' => '3026b2758e66cf11',
'wmv' => '3026b2758e66cf11',
'wri' => 'be000000ab',
'7z' => '377abcaf271c',
'psd' => '38425053',
'sle' => '414376',
'asx' => '3c',
'xdr' => '3c',
'dci' => '3c21646f63747970',
'manifest' => '3c3f786d6c2076657273696f6e3d',
'xml' => '3c3f786d6c2076657273696f6e3d22312e30223f3e',
'msc' => 'd0cf11e0a1b11ae1',
'fm' => '3c4d616b65724669',
'mif' => '56657273696f6e20',
'gid' => '4c4e0200',
'hlp' => '4c4e0200',
'dwg' => '41433130',
'syw' => '414d594f',
'abi' => '414f4c494e444558',
'aby' => '414f4c4442',
'bag' => '414f4c2046656564',
'idx' => '5000000020000000',
'ind' => '414f4c494458',
'pfc' => '414f4c564d313030',
'org' => '414f4c564d313030',
'vcf' => '424547494e3a5643',
'bin' => '424c4932323351',
'bmp' => '424d',
'dib' => '424d',
'prc' => '424f4f4b4d4f4249',
'bz2' => '425a68',
'tar.bz2' => '425a68',
'tbz2' => '425a68',
'tb2' => '425a68',
'rtd' => '43232b44a4434da5',
'cbd' => '434246494c45',
'iso' => '4344303031',
'clb' => '434f4d2b',
'cpt' => '43505446494c45',
'cru' => '43525553482076',
'swf' => '465753',
'ctf' => '436174616c6f6720',
'dms' => '444d5321',
'adf' => '5245564e554d3a2c',
'dvr' => '445644',
'ifo' => '445644',
'cdr' => '52494646',
'vcd' => '454e545259564344',
'mdi' => '4550',
'e01' => '4c5646090d0aff00',
'evtx' => '456c6646696c6500',
'qbb' => '458600000600',
'cpe' => '464158434f564552',
'flv' => '464c56',
'aiff' => '464f524d00',
'eml' => '582d',
'gif' => '47494638',
'pat' => '47504154',
'gx2' => '475832',
'sh3' => '4848474231',
'tif' => '4d4d002b',
'tiff' => '4d4d002b',
'mp3' => '494433',
'koz' => '49443303000000',
'crw' => '49491a0000004845',
'cab' => '4d534346',
'lit' => '49544f4c49544c53',
'chi' => '49545346',
'chm' => '49545346',
'jar' => '5f27a889',
'jg' => '4a47040e000000',
'kgb' => '4b47425f61726368',
'shd' => '68490000',
'lnk' => '4c00000001140200',
'obj' => '80',
'pdb' => 'aced000573720012',
'mar' => '4d41723000',
'dmp' => '504147454455',
'hdmp' => '4d444d5093a7',
'mls' => '4d563243',
'mmf' => '4d4d4d440000',
'nvram' => '4d52564e',
'ppz' => '4d534346',
'snp' => '4d534346',
'tlb' => '4d53465402000100',
'dvf' => '4d535f564f494345',
'msv' => '4d535f564f494345',
'mid' => '4d546864',
'midi' => '4d546864',
'dsn' => '4d56',
'com' => 'eb',
'dll' => '4d5a',
'drv' => '4d5a',
'exe' => '4d5a',
'pif' => '4d5a',
'qts' => '4d5a',
'qtx' => '4d5a',
'sys' => 'ffffffff',
'acm' => '4d5a',
'ax' => '4d5a900003000000',
'cpl' => 'dcdc',
'fon' => '4d5a',
'ocx' => '4d5a',
'olb' => '4d5a',
'scr' => '4d5a',
'vbx' => '4d5a',
'vxd' => '4d5a',
'386' => '4d5a',
'api' => '4d5a900003000000',
'flt' => '76323030332e3130',
'zap' => '4d5a90000300000004000000ffff',
'sln' => '4d6963726f736f66742056697375616c',
'jnt' => '4e422a00',
'jtp' => '4e422a00',
'cod' => '4e616d653a20',
'dbf' => '4f504c4461746162',
'oga' => '4f67675300020000',
'ogg' => '4f67675300020000',
'ogv' => '4f67675300020000',
'ogx' => '4f67675300020000',
'dw4' => '4f7b',
'pgm' => '50350a',
'pax' => '504158',
'pgd' => '504750644d41494e',
'img' => 'eb3c902a',
'zip' => '504b0304140000',
'docx' => '504b030414000600',
'pptx' => '504b030414000600',
'xlsx' => '504b030414000600',
'kwd' => '504b0304',
'odt' => '504b0304',
'odp' => '504b0304',
'ott' => '504b0304',
'sxc' => '504b0304',
'sxd' => '504b0304',
'sxi' => '504b0304',
'sxw' => '504b0304',
'wmz' => '504b0304',
'xpi' => '504b0304',
'xps' => '504b0304',
'xpt' => '5850434f4d0a5479',
'grp' => '504d4343',
'qemu' => '514649',
'abd' => '5157205665722e20',
'qsd' => '5157205665722e20',
'reg' => 'fffe',
'sud' => '52454745444954',
'ani' => '52494646',
'cmx' => '52494646',
'ds4' => '52494646',
'4xm' => '52494646',
'avi' => '52494646',
'cda' => '52494646',
'qcp' => '52494646',
'rmi' => '52494646',
'wav' => '52494646',
'cap' => '58435000',
'rar' => '526172211a0700',
'ast' => '5343486c',
'shw' => '53484f57',
'cpi' => 'ff464f4e54',
'sit' => '5374756666497420',
'sdr' => '534d415254445257',
'cnv' => '53514c4f434f4e56',
'cal' => 'b5a2b0b3b3b0a5b5',
'info' => 'e310000100000000',
'uce' => '55434558',
'ufa' => '554641c6d2c1',
'pch' => '564350434830',
'ctl' => '56455253494f4e20',
'ws2' => '575332303030',
'lwp' => '576f726450726f',
'bdr' => '5854',
'zoo' => '5a4f4f20',
'ecf' => '5b47656e6572616c',
'vcw' => '5b4d535643',
'dun' => '5b50686f6e655d',
'sam' => '5b7665725d',
'cpx' => '5b57696e646f7773',
'cfg' => '5b666c7473696d2e',
'cas' => '5f434153455f',
'cbk' => '5f434153455f',
'arj' => '60ea',
'vhd' => '636f6e6563746978',
'csh' => '6375736800000002',
'p10' => '64000000',
'dex' => '6465780a30303900',
'dsw' => '64737766696c65',
'flac' => '664c614300000022',
'dbb' => '6c33336c',
'acd' => '72696666',
'ram' => '727473703a2f2f',
'dmg' => '78',
'lgc' => '7b0d0a6f20',
'lgd' => '7b0d0a6f20',
'pwi' => '7b5c707769',
'rtf' => '7b5c72746631',
'psp' => '7e424b00',
'wab' => '9ccbcb8d1375d211',
'wpf' => '81cdab',
'png' => '89504e470d0a1a0a',
'aw' => '8a0109000000e108',
'hap' => '91334846',
'skr' => '9501',
'gpg' => '99',
'pkr' => '9901',
'qdf' => 'ac9ebd8f0000',
'pwl' => 'e3828596',
'dcx' => 'b168de3a',
'tib' => 'b46e6844',
'acs' => 'c3abcdab',
'lbk' => 'c8007900',
'class' => 'cafebabe',
'dbx' => 'cfad12fe',
'dot' => 'd0cf11e0a1b11ae1',
'pps' => 'd0cf11e0a1b11ae1',
'ppt' => 'd0cf11e0a1b11ae1',
'xla' => 'd0cf11e0a1b11ae1',
'xls' => 'd0cf11e0a1b11ae1',
'wiz' => 'd0cf11e0a1b11ae1',
'ac_' => 'd0cf11e0a1b11ae1',
'adp' => 'd0cf11e0a1b11ae1',
'apr' => 'd0cf11e0a1b11ae1',
'mtw' => 'd0cf11e0a1b11ae1',
'opt' => 'd0cf11e0a1b11ae1',
'pub' => 'd0cf11e0a1b11ae1',
'rvt' => 'd0cf11e0a1b11ae1',
'sou' => 'd0cf11e0a1b11ae1',
'spo' => 'd0cf11e0a1b11ae1',
'vsd' => 'd0cf11e0a1b11ae1',
'wps' => 'd0cf11e0a1b11ae1',
'ftr' => 'd20a0000',
'arl' => 'd42a',
'aut' => 'd42a',
'wmf' => 'd7cdc69a',
'efx' => 'dcfe',
'one' => 'e4525c7b8cd8a74d',
'rpm' => 'edabeedb',
'gho' => 'feef',
'ghs' => 'feef',
'wp' => 'ff575043',
'wpd' => 'ff575043',
'wpg' => 'ff575043',
'wpp' => 'ff575043',
'wp5' => 'ff575043',
'wp6' => 'ff575043',
'jfif' => 'ffd8ff',
'jpe' => 'ffd8ff',
'jpeg' => 'ffd8ff',
'jpg' => 'ffd8ff',
'mof' => 'fffe23006c006900',
'ipa' => '504b03040a',
);
/**
* 检查文件类型
*
* @param string $filepath 文件路径
* @param string $fileext 文件扩展名
*
* @return boolean
*/
public static function validation($filepath, $fileext)
{
// 文件格式未知
if (!isset(self::$_fileformats[$fileext]))
{
return false;
}
$length = strlen(self::$_fileformats[$fileext]);
$bin = self::_readfile($filepath, $length);
$filehead = @unpack("h{$length}", $bin);
// 判断文件头
if (strtolower(self::$_fileformats[$fileext]) == $filehead[1])
{
return true;
}
return false;
}
/**
* 读取文件内容
*
* @param string $filepath 文件路径
* @param integer $size
*
* @return string
*/
private function _readfile($filepath, $size)
{
$file = fopen($filepath, "rb");
$bin = fread($file, $size);
fclose($file);
return $bin;
}
}
?>
调用
复制代码 代码如下:
require './class_filetypevalidation.php';
// 文件路径
$filepath = "d:/test.png";
$x = filetypevalidation::validation($filepath, 'zip');
var_dump($x);
上一篇: 超小PHP小马小结(方便查找后门的朋友)
下一篇: PHP中的错误处理、异常处理机制分析