<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>php file upload only allow image file upload </title>
<body>
<form id= "Form1" Name= "Form1" enctype= "Multipart/form-data" method= "POST" action= "" >
<label>
<input type= "File" name= "file"/>
</label>
<label>
<input type= "Submit" name= "Submission" value= "submitted"/>
</label>
</form>
</body>
<?php
if ($_files) {
foreach ($_files as $key => $_value)
{
$_files[$key] [' type '] =$_value[' type '];
}
if (substr ($_files[$key] [' type '],0,6]!= ' image/')
{
Exit
}
}
Echo ' Print_r ($_files);
Echo ' echo Var_export ($_files);
?>
First, judge the $_files[' inputname ' [' type '], correct the file suffix for the type that can be identified, and then judge the suffix.
Because $_files[' inputname ' [' type '] can only recognize a few types, it is based on the contents of the file, especially for many cameras that save BMP graphics as JPG files, and your program may be converted to JPG for BMP processing.