Php obtains the file type of the uploaded file name.

Source: Internet
Author: User

Php Tutorial: get the file type of the uploaded file name

$ Imgname = $ _ FILES ["file"] ["name"]; // get the name of the uploaded file
$ Filetype = pathinfo ($ imgname, PATHINFO_EXTENSION); // get the suffix
$ Newname = date ("Ymdhis"). ".". $ filetype; // create a new name

Check again

$ File = 'www.bKjia.c0m.gif ';
Echo getfix ($ file );

// The obtained value is gif. This method is the simplest and the most practical. Let's take a look at method 2. This method reads the extension using substr.

 

$ File named 'aaa.gif ';
Echo substr ($ file, strpos ($ file, '.') + 1 );

// Method 3 Use Arrays

$ File = '111cn.gif ';
$ D111cn = explode ('.', $ file );
Echo $ d111cn [count ($ d111cn)-1];

Function getfix ($ l1 ){
Return end (explode ('.', $ l1 ));
}

 

$ Extname = substr ($ upload_file_name, strpos ($ upload_file_name, ".") + 1); // get the file extension

The strpos () function returns the position where the string first appears in another string. If this string is not found, false is returned.

 

For more details, see http://www.bKjia. c0m/phper/21/358 ad3dd52a90fd7894a1047adc80208.htm

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.