PHP provides four methods to obtain the file extension.

Source: Internet
Author: User
PHP can obtain the file extension in four ways ,. PHP provides four methods for obtaining the file extension. This article describes four methods for obtaining the file extension by PHP. For your reference, refer to "export filename123.jpg". Method 1: four methods for obtaining file extensions in PHP,

This article describes four methods for obtaining the file extension of PHP. 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.

Example: This article describes four methods for PHP to obtain the file extension. For your reference, see $ filename = "123.jpg"; // method 1...

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.