图片上传中,文件的校验

    技术2022-05-11  123

    图片上传中,文件的校验      来源:奥索网      图片上传中,文件的校验作者:tonglw

    这是我的一点心得,希望能对大家有所帮助。有不足之处请大家包涵,多多指教。

    客户端校验

    <html> <head> <meta http-equiv="Content-Language" content="zh-cn"> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta name="GENERATOR" content="Microsoft FrontPage 4.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <title>选择图片</title> <SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript> <!-- Sub button1_onclick if trim(window.form1.file1.value)="" then alert "选择图片!" exit sub end if

    sfile=trim(window.form1.file1.value) sfile=ucase(right(sfile,4)) if sfile=".JPG" or sfile=".GIF" then window.form1.submit else alert "选择 *.JPG 或 *.GIF 文件!" exit sub end if End Sub

    Sub file1_onfocus sfile=window.form1.file1.value sfile=ucase(right(sfile,4)) if sfile=".JPG" or sfile=".GIF" then window.form1.photo.style.visibility="visible" window.form1.photo.src =window.form1.file1.value end if End Sub --> </SCRIPT> </head> <body style="font-size: 9pt"> <p align="center">选择图片</p> <FORM action="add.php" method=POST method=post enctype="multipart/form-data" id=form1 name=form1> <div align="center"> <center> <table border="1" cellspacing="0" width="354" style="font-size: 9pt" bordercolorlight="#000000" bordercolordark="#FFFFFF"> <tr> <td width="350" colspan="2" align="center"><img id=photo border="0" src="" style="visibility:hidden" height="50"></td> </tr> <tr> <td width="83" align="right">选择图片:</td> <td width="267"><INPUT type="file" id=file1 name=file1></td> </tr> <tr> <td width="350" colspan="2" align=center><br> <INPUT type="button" value="提交" id=button1 name=button1></td> </tr> </table> </center> </div> </FORM> </body> </html>

    ------------------------------------------------------------------

    服务器端校验 add。php 校验部分

    <?php

    if(!(($file1_type=="image/gif")||($file1_type=="image/pjpeg"))) { echo "<div align=center ><a href='javascript:window.history.back(-1) ; ' >请选择GIf或JPEG的文件 ,后退</a></div>"; exit ;

    }

    ?>


    最新回复(0)