(ת)¿Í»§¶ËÑéÖ¤ÉÏ´«Îļþ´óС(¼æÈÝIEºÍ»ðºü)(2)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUploadTest.aspx.cs" Inherits="FileUploadTest" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>www.liehuo.net</title> <style type="text/css"> #File1 { height: 22px; width: 264px; } </style> <script language="javascript" type="text/javascript"> function disableSave(obj) { var btnsave = document.getElementById("Button2"); btnsave.disabled = true; } function validateFileSize(id,maxsize) { var btnsave = document.getElementById("Button2"); btnsave.disabled = false; var filepath = ""; var fileupload = document.getElementById(id); if (fileupload.value.length < 5) { alert('ÇëÑ¡ÔñÎļþ£¡'); return; } var agent = window.navigator.userAgent; if (document.all) { var isIE7 = agent.indexOf('MSIE 7.0') != -1; var isIE8 = agent.indexOf('MSIE 8.0') != -1; //IE7ºÍIE8»ñµÃÎļþ·¾¶ if (isIE7 || isIE8) { fileupload.select(); filepath = document.selection.createRange().text; } //IE6»ñµÃÎļþ·¾¶ else { filepath = file.value; } PageMethods.ValidateFile(filepath, maxsize, ieCallBack); } if (agent.indexOf("Firefox") >= 1) { if (fileupload.files) { var size = fileupload.files[0].fileSize; if (size > parseInt(maxsize)) { fileupload[removed][removed] = '<input type="file" name="' + fileupload.name + '" id="' + fileupload.id + '" onchange="disableSave(this);"/> '; alert("Îļþ³¬¹ý´óС£¡"); } else { alert("ÎļþÉÏ´«³É¹¦£¡"); } } } } function ieCallBack(response) { if (response == "invalid") { var file = document.getElementById('FileUpload1'); file[removed][removed] = '<input type="file" name="' + file.name + '" id="' + file.id + '" onchange="disableSave(this);"/> '; alert("Îļþ³¬¹ý´óС£¡"); } else { alert("ÎļþÉÏ´«³É¹¦£¡"); } } </script> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"> </asp:ScriptManager> <div> <div style="text-align:center"> JavaScriptÑéÖ¤¿Í»§¶ËÉÏ´«Îļþ´óС <br />²»ÆôÓð²È«ÉèÖ㬼æÈÝIE»ðºü <br /> <span> <input id="FileUpload1" type="file" onchange="disableSave(this);" runat="server"/></span> <input id="Button1" type="button"value="ÉÏ´«Îļþ" onclick="validateFileSize('FileUpload1','102400');"/> <br /> <asp:Button ID="Button2" runat="server" Text="±£´æ¼Ç¼" onclick="Button2_Click" /> <br /> ÑéÖ¤Îļþ´óС䳬¹ýÖ¸¶¨Öµºó£¬¸øTEXTBOX¸³Öµ <br /> <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Height="84px" Width="348px"></asp:TextBox> <br /> Éè¼Æ˼·£ºµ±Óû§Ñ¡Ôñ¡°ä¯ÀÀ¡±½«¡°±£´æ¼Ç¼¡±°´Å¥½ûÓã¬<br /> Ö»Óо¹ý¡°ÉÏ´«Îļþ¡±°´Å¥ÑéÖ¤ÒÔºó²ÅÄÜÌá½»¼Ç¼¡£<br /> ÑéÖ¤²»Í¨¹ýÔò½«ÉÏ´«¿Ø¼þµÄÖµÇå¿Õ£¬Í¨¹ýÔò²»×÷´¦Àí¡£ </div> </div> </form> </body> </html> ºǫ́´úÂ룺´úÂë using System; using System.IO; using System.Web.Services; public partial class FileUploadTest : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } pbotected void Button2_Click(object sender, EventArgs e) { TextBox1.Text = "Äã³É¹¦µÄÉÏ´«ÁËÎļþ" + FileUpload1.PostedFile.FileName; } [WebMethod] public static string ValidateFile(string filepath, string filezie) { var fs = new FileStream(filepath, FileMode.Open, FileAccess.Read); if (fs.Length > int.Parse(filezie)) return "invalid"; return "valid"; } }
ÍƼöÐÅÏ¢
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- jQuery Tooltips²å¼þ
- jQueryµÄ.bind()¡¢.live()ºÍ.delegate(....
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- Ä㲻ϲ»¶»ðºü£¬µ«ÓÖϲ»¶firebug£¬ÄǾ͸úÎÒÒ»ÆðÀ´ÔÚIEÉÏ....
- ¸ù¾ÝÏÔʾÆ÷·Ö±æÂʵ÷ÕûÒ³ÃæÏÔʾµÄJavascript½Å±¾
- jQuery дµÄ·ÂÐÂÀË΢²© ÏòϹö¶¯Ð§¹û¡¾×ªÔØ¡¿
- ͨÓõÄJqueryÑ¡ÔñÆ÷
- jQuery ½áºÏ Json Ìá½»Êý¾Ýµ½Webservice£¬....
- ×ÔÖÆjQueryÖÇÄÜÌáʾ²å¼þһö
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- js»ñÈ¡srcÖд«µÝµÄ²ÎÊý
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- ÈÃä¯ÀÀÆ÷ÆÁ±ÎµôJavaScriptµÄ³ö´íÌáʾ
- github²»ÄܼÓÔØcss¡¢js½â¾ö°ì·¨
- ÎÒÖªµÀµÄJavaScript -- Éè¼Æģʽ(ÇŽÓ)Ó¦ÓÃÖ® ¨C ....
- 15¸öÖµµÃ¿ª·¢ÈËÔ±¹Ø×¢µÄjQuery¿ª·¢¼¼ÇɺÍÐĵÃ
- dz̸JavascriptÃæÏò¶ÔÏó±à³Ì
- JS¼òµ¥¶¯»·â×°
- JavaScript³õѧÕßӦעÒâµÄÆ߸öϸ½Ú
- jQuery Tooltips²å¼þ
ÆÀÂÛ