Php judges the file upload type and filters insecure data ,. Php judges the file upload type and the method of filtering unsafe data. This article describes how php judges the file upload type and filters unsafe data. Share it with you for your reference. Php is used to determine the file upload type and filter insecure data,
This article describes how to use php to determine the file upload type and filter insecure data. Share it with you for your reference. The details are as follows:
It is not allowed to upload files other than image files. if you are prompted, 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 limited, but if you use an image, it is enough to understand. function, filter unsafe characters, the instance function code is as follows:
The code is as follows:
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 unsafe characters
$ String = addslashes ($ string );
}
}
Return $ string;
}
// Usage example:
$ _ COOKIE = c_addslashes ($ _ COOKIE );
$ _ POST = c_addslashes ($ _ POST );
$ _ GET = c_addslashes ($ _ GET );
// Add a public file
If ($ _ FILES ){
Foreach ($ _ FILES as $ key =>$ _ value)
{
$ _ FILES [$ key] ['type'] = $ _ value ['type'];
}
If (substr ($ _ FILES [$ key] ['type'], 0, 6 )! = 'Image /')
{
Exit;
}
}
I hope this article will help you with PHP programming.
Example: This article describes how php judges the file upload type and filters insecure data. Share it with you for your reference. With...