Home  >  Article  >  Backend Development  >  PHP gets the file type of the uploaded file name_PHP tutorial

PHP gets the file type of the uploaded file name_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:59:181413browse

php tutorial to get the file type of the uploaded file name

$imgname = $_FILES["file"]["name"]; //Get the uploaded file name
$filetype = pathinfo($imgname, PATHINFO_EXTENSION);//Get the suffix
$newname = date("Ymdhis").".".$filetype; //Build a new name

See you again

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

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

$file ='aaa.gif';
echo substr($file,strpos($file,'.')+1);

//Method 3 still use array

$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 of the first occurrence of a string in another string. If the string is not found, returns false.

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631331.htmlTechArticlephp tutorial to get the file type of the uploaded file name $imgname = $_FILES[file][name]; //Get Uploaded file name $filetype = pathinfo($imgname, PATHINFO_EXTENSION);//Get the suffix $newna...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn