最近工作中需要做一个上传图片的功能,既然上传的是图片,那么就应该在上传之前对文件进行一下验证,看看要上传的是不是图片文件。所以在上传之前要对所选文件的格式进行验证。上传图片时因为服务器资源有限,经常会规定图片最大不超过多少,所以在上传之前还要进行图片大小的一个验证。今天就让我们来做一下这两个验证。 验证文件类型,看看所选文件是不是图片: 代码如下://文件类型: protected bool IsAllowableFileType(stri...
代码如下:HttpPostedFile UpFile = File1.PostedFile;int FileLenght = UpFile.ContentLength;decimal FileSize = FileLenght / 1024;if (FileLenght == 0){ DIVShowGVError.Visible = true; LblShowGVError.Text = "请选择上传文件"; return;}string strImageName = UpFile.FileName;string strImageType = strImageName.Substring(strImageName.LastIndexOf(".")).ToLower();if (strImageType != ".jpg" && strImageTyp...
代码如下: #region 上传Execl文件 protected void Button1_Click(object sender, EventArgs e) { if (FileUpload1.HasFile) { string NewFileName = string.Empty; string ErrorMess = UpLoadFile(FileUpload1, ".xls|.xlsx", 1024 * 5, Server.MapPath("/Report/SocialApply/"), 1, out NewFileName); if (string.IsNullOrEmpty(ErrorMess)) { ...
ASP.NET依托.net framework类库,封装了大量的功能,使得上传文件非常简单,主要有以下三种基本方法。 方法一:用Web控件FileUpload,上传到网站根目录。 Test.aspx关键代码:代码如下: <form id="form1" runat="server"> <asp:FileUpload ID="FileUpload1" runat="server" /> <asp:Button ID="Button1" runat="server" Text="上传" OnClick="Button1_Click" /> <asp:Label ID="Label1" runat="server" Text="" St...
修改Webcong文件: 以下为引用的内容: 代码如下:<system.web> <httpRuntime maxRequestLength="40690" useFullyQualifiedRedirectUrl="true" executionTimeout="6000" useFullyQualifiedRedirectUrl="false" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100" enableVersionHeader="true" /> </system.web> 其中与上传有密切关系的是: 代码如下:maxRequestLength 指示 ASP.NET 支持的最大文件上...
效果:思路: 首先,获取图片物理地址,然后进行判断将图片保存到文件夹下,再将图片的信息保存到数据库。 数据库: 代码如下:create table image1(ID int identity(1,1) primary key,ImageName varchar(100) ,ImageType varchar(20),ImagePath varchar(200)) 代码: 代码如下:<body> <form id="form1" runat="server"> <div> <table> <tr> <td colspan="2" style="height: 21px"> ...
Uploadify是JQuery的一个上传插件,实现的效果非常不错,带进度显示。Uploadify官方网址:http://www.uploadify.com/,在MVC中使用的方法可以参考 jQuery Uploadify在ASP.NET MVC3中的使用 和 Asp.net Mvc中使用uploadify实现图片缩放保存。 本文是一个简单的介绍Demo,主要是动态传递参数方法:通过formdata 向处理程序传递额外的表单数据:代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww...
代码如下:[HttpPost] public Task<Hashtable> ImgUpload() { // 检查是否是 multipart/form-data if (!Request.Content.IsMimeMultipartContent("form-data")) throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); //文件保存目录路径 string SaveTempPath = "~/SayPlaces/" + "/SayPic/SayPicTemp/"; String dirTempPath = HttpContext.Current.Server.MapPath(SaveTempPath); ...
第一、图片上传,代码如下:xxx.aspx 代码如下: <td class="style1"> <asp:FileUpload ID="FileUpload1" runat="server" /> <asp:Button ID="Button1" runat="server" Text="上传一般图片" onclick="Button1_Click" /> </td> <td class="style3"> <asp:Image ID="Image1" runat="server" Height="200px" Width="200px" /> </td>xxx.aspx.cs ...
代码如下:[HttpPost] public string UploadImage() { //string ss = Request.Form["uploadFile"]; //return ss; HttpPostedFileBase uploadFile = Request.Files[0]; string fileName = uploadFile.FileName; int fileSize = uploadFile.ContentLength; string fileExt = Path.GetExtension(fileName).ToLower(); string message = ""; if (!(fileExt == ".png" || fileExt == ".gif" || fileExt == ".jpg" || fileExt == ".jpeg")...
代码如下:using System;using System.Globalization;using System.Collections;using System.Configuration;using System.Data;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;public partial class Jscript_KindEditor_upload_cgi_upload : System.Web.UI.Page{protected void Page_Load(object s...
代码如下:<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>Files uploaded to server</h2> <div id="dialog" title="Upload files"> <% using (Html.BeginForm("Upload", "File", FormMethod.Post, new { enctype = "multipart/form-data" } )) {%> <br /> <p><input type="file" id="fileUpload" name="fileUpload" si...
客户端: 代码如下: /// <summary> /// 写入数据到流中 /// </summary> /// <param name="url"></param> /// <param name="callback"></param> public async static Task<bool> Write(string url, Stream clientStream) { if (clientStream.Length > 25*1024*1024) url += "&t=1"; // 表示上传大文件 try { Up(url, clientStream); ...
出于安全性能的考虑,目前js端不支持获取本地图片进行预览,正好在做一款类似于QQ心情的发布框,找了不少jquery插件,没几个能满足需求,因此自己使用SWFuplad来实现这个图片上传预览。 先粘上以下插件,在别的图片上传功能说不定各位能用的上。 1、jQuery File Upload Demo地址:http://blueimp.github.io/jQuery-File-Upload/ 优点是使用jquery进行图片的异步上传,可控性好,可根据自己的需求任意定制; 缺点是在IE9等一些浏览器...
在页面上放入一个上传控件和一个图片控件. 代码如下: <asp:FileUpload ID="FileUpload1" runat="server" onpropertychange="show(this.value)"/> <asp:Image ID="Image1" runat="server" /> 在上传控件中写onpropertychange="show(this.value)"事件并调用js中的show函数并将自身的参数传进js. 代码如下: <script type="text/javascript"> function show(id) ...{ document.getElementById("Image1").src...