文件上传控件具有上传限制和要上传的选定文件 [英] file upload control having upload limit and selected files to upload

查看:105
本文介绍了文件上传控件具有上传限制和要上传的选定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用文件上传控件和文件类型(例如只有.jpg或.jpeg)或任何其他格式设置要上传的文件的限制,以便它不应超过文件大小和要上传的格式类型。

等待得到答案.........

i have to set a limit of file to be uploaded using file upload control and the type of file (" e.g only .jpg or .jpeg ") or any other format , so that it should not exceed the file size and the type of format to be uploaded.
Waiting To get Answer.........

推荐答案

设置 maxRequestLength httpRuntime 中的c $ c>属性。

有关教程,请访问 http://msdn.microsoft.com/en-us/library/aa479405.aspx [ ^ ]。





另一种选择是在上传按钮的点击事件中检查文件大小

例如

Set the maxRequestLength property in httpRuntime in your config file.
For a tutorial, visit http://msdn.microsoft.com/en-us/library/aa479405.aspx[^].


The other option would be to check the file size in the upload button''s click event
e.g.
HttpPostedFile file = (HttpPostedFile)file;
    if ((file != null) && (file.ContentLength > 1024))



现在检查尺寸在 file.ContentLength 上并正确提示消息。


如果flash不是您环境中的约束, [ SWFUpload ] [ ^ ]非常擅长满足您的要求要求非常灵活。



对于基于非Flash的替代方案,您可以在IE中使用ActiveX脚本(如果客户端有限制,有时会不屈不挠)和Javascipt对于其他浏览器。你可以在这里找到一些例子 - http:// www .kavoir.com / 2009/01 / check-for-file-size-with-javascript-before-uploaded.html [ ^ ]



干杯
If flash is not a constraint in your environment, [SWFUpload][^] is quite good at meeting your requirements and quite flexible.

For a non-flash based alternative, you may use ActiveX scripting in IE (unyielding at times if there are restrictions on client side) and Javascipt for other browsers. you may find some examples here - http://www.kavoir.com/2009/01/check-for-file-size-with-javascript-before-uploading.html[^]

Cheers


这篇关于文件上传控件具有上传限制和要上传的选定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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