This article mainly introduces four methods for PHP to obtain the file extension, which involve PHP's operations on strings, arrays, uploaded file attributes, and other related skills. it has some reference value, for more information about how to obtain the file extension in PHP, see the following example. We will share this with you for your reference. The details are as follows:
$ Filename = "123.jpg"; // Method 1: function get_ext ($ file_name) {return array_pop (explode ('. ', $ file_name); // use. grouping strings} echo get_ext ($ filename); // Method 2: $ fileEx = strtolower (substr (strrchr ($ filename ,". "), 1); echo $ fileEx; // method 3: $ extend = pathinfo ($ filename); echo $ extend ['extension']; // method 4: $ filetype = array ("image/gif", "image/jpeg "); // Determine whether the file extension type is in this array if (in_array ($ _ FILES ['file'] ['type'], $ filetype )) {// Determine echo $ _ FILES ['file'] ['type'] for uploaded FILES;}
I hope this article will help you with PHP programming.