Php obtains the file type of the uploaded file name. Php Tutorial: get the file type of the uploaded file name $ imgname $ _ FILES [file] [name]; get the name of the uploaded file $ filetypepathinfo ($ imgname, PATHINFO_EXTENSION ); get the suffix $ newna 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
Parameters $ imgname = $ _ FILES [file] [name]; // Obtain the name of the uploaded file $ filetype = pathinfo ($ imgname, PATHINFO_EXTENSION ); // Get the suffix $ newna...