Determine the File Upload type and filter insecure data in the php tutorial
This function filters insecure characters
Function s_addslashes ($ string, $ force = 0 ){
If (! Get_magic_quotes_gpc ()){
If (is_array ($ string )){
Foreach ($ string as $ key => $ val ){
$ String [$ key] = s_addslashes ($ val, $ force );
}
} Else {
$ String = str_replace ("& # x", "& # x", $ string );//
Filter insecure characters
$ String = addslashes ($ string );
}
}
Return $ string;
}
Instance:
$ _ COOKIE = c_addslashes ($ _ COOKIE );
$ _ POST = c_addslashes ($ _ POST );
$ _ GET = c_addslashes ($ _ GET );
Add public files
If ($ _ FILES ){
Foreach ($ _ FILES as $ key =>$ _ value)
{
$ _ FILES [$ key] ['type'] = $ _ value ['type'];
}
If (substr ($ _ FILES [$ key] ['type'], 0, 6 )! = 'Image /')
{
Exit;
}
}
Uploading of files other than image files is prohibited,
Tip:
Do not obtain the file extension to determine the type. This is the least secure. We use $ _ FIlES ['form']
['Type']
This can read the file content to identify the file type, but it can recognize only limited, but if you use images
Understanding.
Www.111cn.cn original site, reprinted with instructions