PHP Tutorial To determine the file type of upload file multiple instance code
$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 (' Your uploaded file type is not allowed ');
Exit;
}
/*
function Resolution:
Array Array This does not say
strtolower characters to lowercase
substr character interception, the Chinese processing is not friendly.
Strrpos The position where the character appears in the specified string
explode split function, return result array
End read Data last value
$_files global variable file upload
getimagesize Get the type of picture
In_array Determines if the variable is in an array
exit terminates the current script run
*/
&NBSP