JS获取文件的扩展名

 JavaScript  2021-05-26  admin  794  1071

/**
 * JS获取文件的扩展名
 * @param {Object} fileName
 */
function getFileExt(fileName) {
    //var rExt = /\.([^.]+)$/;
    var ext = /\.([^.]+)$/.exec(fileName) ? RegExp.$1.toLowerCase() : '';
    return ext;
}

alert(getFileExt('centphp.jpg')); // jpg
alert(getFileExt('centphp.com.jpg')); // jpg


如果文章对您有帮助,点击下方的广告,支持一下作者吧!

转载必须注明出处:

JS获取文件的扩展名 —— centhp.com

相关推荐


go语言生成ssl网站证书

在go的x509包下有go定义的证书的结构packagemain import( "crypto/ecdsa" "crypto/elliptic" "crypto/rand" "crypto/x509" "crypto/x509/pkix" "encoding

Ghostscript pdf转图片的常用方法

Ghostscript是PostScript®语言和PDF文件的解释器。它可以根据GNU GPL Affero许可证获得,也可以从Artifex Software,Inc.获得商业使用许可。它已经积极开发了30多年,在此期间已经移植到多个不同的系统。Ghostscript由PostScript解释器层和图形库组成。https://www.ghostscript.com/ gswin64c.exe

php 判断远程文件是否存在

php 判断远程文件是否存在if(!function_exists('check_remote_file_exists')){ /** *判断远程文件是否存在. *@param$urlstringhttp或https开头的绝对地址 *@returnstring *@Date:2020-07-3116:47:06 *@Author:centphp.com */ fun

php 保存远程图片到本地

/** *保存远程图片到本地 *@paramstring$avatar *@returnbool|string */ functionsaveRemoteImage($url,$filename='') { if($url==''){ returnfalse; } try{ if($filename==''){ $ex