< body> File extension verification &l"/> check file < body> File extension verification &l">

Home  >  Article  >  Backend Development  >  How to use php to determine file extension

How to use php to determine file extension

一个新手
一个新手Original
2017-09-12 10:14:151869browse


<!DOCTYPE>
<html>
<head>
    <meta http-equiv="Content-type" content="text/html" charset="utf-8">
    <title>check file</title>
</head>
<body>
<b>文件扩展名验证</b>
<input type="text" name="int" value="文件.php" onblur="check(this)" id="int">
<input type="button" value="检测" onclick="check_value()">
<script>    function check(obj){        
    if(obj.value == "" || obj.value.length<3){
            alert("输入的长度不能小于3且不能为空!");
            obj.focus();
        }
    }    function check_value(){        var str = $("int").value;        var repx = /\.(php|asp|jsp)$/i;        var type = str.substring(str.lastIndexOf("."),str.length);        if(type.match(repx) && str.lastIndexOf(".") != -1){
            alert("文件扩展名正确");
            $("int").focus();
        }else{
            alert("文件扩展名有误");
            $("int").focus();
        }
    }    function $(obj){        return document.getElementById(obj);
    }</script>
</body>
</html>

The above is the detailed content of How to use php to determine file extension. For more information, please follow other related articles on the PHP Chinese website!

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