如何使用文件上传控件进行过滤 [英] how to filter by using fileupload control

查看:78
本文介绍了如何使用文件上传控件进行过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用文件上传控件将图片过滤到数据库中,然后再给我发送指南或任何摘要
过滤图像类型

I want to filter pics before into database by using fileupload control can u send me guide lines or any snippets
filtering of images types

推荐答案

您可以使用RegEx进行验证,请参见下面的示例

you can validate with RegEx See the Example below

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
function validate() {
var uploadcontrol = document.getElementById('<%=FileUpload1.ClientID%>').value;
//Regular Expression for fileupload control.
var reg = /^(([a-zA-Z])|(\\{2}\w+)\


?)(\\(\ w [\ w].*))+(.doc | .docx | .DOC | .DOCX)
?)(\\(\w[\w].*))+(.doc|.docx|.DOC|.DOCX)


/; 如果(uploadcontrol.length> 0 ) { // 检查控件值. 如果(reg.test(uploadcontrol)) { 返回 ; } 其他 { // 如果不满足条件将显示错误消息. alert(" ); 返回 ; } } } // 功能结束验证. < / 脚本 > < /head > < 正文 > < 表单 =" form1" runat >服务器" > < div > < =" center" < tr > < td > 限制文件上传示例 < br / < asp:fileupload id =" runat 服务器" xmlns:asp #unknown" / > < br > < asp:button id =" runat 服务器" 文本 按钮" onclientclick 返回validate();" xmlns:asp #unknown" / < br > < asp:label id =" runat 服务器" forecolor 红色" xmlns:asp =" > < /asp:label > < /td > < /tr > < /table > < /div > < /form > < /body > < /html >
/; if (uploadcontrol.length > 0) { //Checks with the control value. if (reg.test(uploadcontrol)) { return true; } else { //If the condition not satisfied shows error message. alert("Only .doc, docx files are allowed!"); return false; } } } //End of function validate. </script> </head> <body> <form id="form1" runat="server"> <div> <table align="center"> <tr> <td> Restrict File Upload sample <br /> <asp:fileupload id="FileUpload1" runat="server" xmlns:asp="#unknown" /> <br /> <asp:button id="Button1" runat="server" text="Button" onclientclick="return validate();" xmlns:asp="#unknown" /> <br /> <asp:label id="Label1" runat="server" forecolor="Red" xmlns:asp="#unknown"></asp:label> </td> </tr> </table> </div> </form> </body> </html>


其他链接参考
http://mindstick.com/Articles/7d72a758-52bc-4242-922f -6b3914895d92/?Validating%20FileUpload%20contro [ http://forums.asp.net/p/1051895/2171502.aspx [ ^ ]


希望这对您有帮助
不要忘记投票或接受解决方案
谢谢


Other Link Reference
http://blogs.msdn.com/b/asmitaw/archive/2008/09/18/validating-image-file-for-content-type-with-asp-net-fileupload-web-control.aspx[^]
http://mindstick.com/Articles/7d72a758-52bc-4242-922f-6b3914895d92/?Validating%20FileUpload%20contro[^]
http://forums.asp.net/p/1051895/2171502.aspx[^]


hope this will help you
dont forget to vote or accept solution
thanks


这篇关于如何使用文件上传控件进行过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆