欢迎访问:常州市武进区嘉泽中心小学网站 !今天是:
栏目列表
您现在的位置是:首页>>教师>>计算机技术>>网站制作技术>>文章内容
图片上传中,文件的校验
发布时间:2008-11-20   点击:   来源:本站原创   录入者:佚名
 

图片上传中,文件的校验
      来源:奥索网
  
  图片上传中,文件的校验
作者: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 ;

}

?>


附件:
    关闭窗口
    打印文档
    账号登录
    保持登录 忘记密码?
    账号与武进教师培训平台同步