PHP prohibits certain types of upload files _php tutorial

Source: Internet
Author: User
To prevent some people from uploading executables such as EXE to the server, we can write a program to determine the type of upload file, then the non-conforming type of the file will reject the upload.

Here are the PHP programs that implement this feature:

function ($file _name, $pass _type = array (' jpg ', ' jpeg ', ' gif ', ' BMP ', ' png ')) {    //allow the suffix of the file type to consist of an array    $file = $pass _ type;    The suffix of the file name that intercepts the uploaded file    $kzm  = substr (STRRCHR ($file _name, "."), 1);    Determines whether the suffix is in the array    $is _img = In_array (Strtolower ($KZM), $file);    if ($is _img)    {        return true;    }    else    {        return false;}    }

In_array () function

The In_array () function searches the array for the given value. Usage: In_array (value,array,type).

    • Parameter value, required. Specifies the value to search for in the array.
    • parameter array, required. Specifies the array to search for.
    • parameter type, optional. If set to true, checks whether the searched data is the same as the type of the array's value.

Returns true if the given value exists in an array of arrays. If the third argument is set to True, the function returns true only if the element exists in the array and the data type is the same as the given value.

If no arguments are found in the array, the function returns FALSE.

If the value parameter is a string, and the type parameter is set to True, the search is case-sensitive.

 
  

Program output:

Match found

One more example program:

 
  ";} else{  echo "Match not found
";} if (In_array ("Glenn", $people, TRUE)) { echo ' Match found
";} else{ echo "Match not found
";} if (In_array ($people, TRUE)) { echo ' Match found
";} else{ echo "Match not found
";}? >

Program output:

Match not Foundmatch Foundmatch found

http://www.bkjia.com/PHPjc/752447.html www.bkjia.com true http://www.bkjia.com/PHPjc/752447.html techarticle to prevent some people from uploading executables such as EXE to the server, we can write a program to determine the type of upload file, then the non-conforming type of the file will reject the upload. The next ...

  • 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.