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