$array = array (' jpg ', ' gif ', ' PNG ', ' jpeg ');
$PICIMG = '/upfile/upload_pic/thumbnail_1258615556.jpg ';
$img = Strtolower ($PICIMG);
Get file name extension method one
$ext = substr ($img, Strrpos ($img, '. ') +1)//Here is the code to read the file name extension
Get file name extension method two
$ext = End (Explode ('. ', $img));
Get file name extension method Three this is supposed to be the safest, is to use PHP $_files[' type '
$ext = $_files[' file ' [' type '];
Get file name extension method four
$ext = getimagesize ($img);//This function returns an array
if (!in_array ($ext, $array))
{
Exit (' Thumbnail address error, please upload again! ');
}
Else
{
Echo (' The type of file you uploaded is not allowed ');
Exit
}
/*
Function parsing:
Array arrays this doesn't say.
Strtolower convert characters to lowercase
substr character interception, not friendly to Chinese processing.
Strrpos the position in the specified string where the character of the judge appears
Explode Split function, returns the result as an array
End reads the last value of the data
$_files global variable File upload
GetImageSize get the type of picture
In_array determine if the variable is in the array
Exit terminates current script run
*/
/*
Fdsfds
This site original article reproduced annotated from Www.111cn.net
*/
?>