Php judges the File Upload type and filters insecure data

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.