input type="file" 上传文件,若是flv格式,则截取保存一张图片asp.net
来源:互联网 发布:java socket通信 编辑:程序博客网 时间:2024/05/04 07:41
前台:
<input width="200px" class="TextClass" id="AttachInfo" runat="server" type="file" /> <asp:Label ID="lbl_AttachInfo" runat="server"></asp:Label> <asp:Button ID="btnUpload" runat="server" Text="上传" OnClick="btnUpload_Click" />
后台:
protected void btnUpload_Click(object sender, EventArgs e) { string RowGuid = Guid.NewGuid().ToString(); //获取文件名 string FilePath = AttachInfo.Value; //文件后缀名 string suffixName = FilePath.Substring(FilePath.LastIndexOf('.')); //附件大小 int FileLen = AttachInfo.PostedFile.ContentLength; lbl_AttachInfo.Text = FileLen.ToString(); //将flv格式的文件重新保存一份图片 if (suffixName.ToUpper() == ".FLV") { string strAttURL = System.Web.HttpContext.Current.Server.MapPath("~/TempFile/") + RowGuid + "\\";//服务端保存的路径 if (Directory.Exists(strAttURL) == false)//如果不存在就创建file文件夹 { Directory.CreateDirectory(strAttURL); } AttachInfo.PostedFile.SaveAs(strAttURL + AttachInfo.PostedFile.FileName);//将文件保存在服务器的路径上 CatchImg(AttachInfo.PostedFile.FileName, RowGuid, System.Web.HttpContext.Current.Server.MapPath("~/TempFile/")); } } #region 从视频中截取一张图片保存 public string CatchImg(string fileName, string RowGuid, string strAttPath) { string sizeOfImg = "240x180"; string ffmpeg = HttpContext.Current.Server.MapPath("~/ffmpeg/ffmpeg.exe"); string flv_img = fileName.ToLower().Replace(".flv", ".jpg"); string TostrFullFilePath = strAttPath + RowGuid + "\\" + flv_img; string strFullFilePath = strAttPath + RowGuid + "\\" + fileName;//客户端路径 string strPartUrl = System.Web.HttpContext.Current.Request.ApplicationPath + "/" + "TempFile/" + RowGuid + "/" + flv_img; if (!File.Exists(TostrFullFilePath)) { string FlvImgSize = sizeOfImg; // System.Diagnostics.ProcessStartInfo ImgstartInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg); ImgstartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; // ImgstartInfo.Arguments = " -i " + strFullFilePath + " -y -f image2 -ss 2 -vframes 1 -s " + FlvImgSize + " " + TostrFullFilePath; try { System.Diagnostics.Process.Start(ImgstartInfo); } catch { return ""; } //flv_img if (System.IO.File.Exists(TostrFullFilePath)) { return strPartUrl; } return ""; } else { return strPartUrl; } } #endregion }
注文件ffmpeg.exe 在自己的百度网盘下载,文件夹名为ffmpeg
将文件保存为流,入库
public static byte[] RetriveUploadFileByte(HtmlInputFile iFile) { if (iFile.PostedFile.ContentLength > 0) { byte[] buffer = new byte[iFile.PostedFile.ContentLength]; iFile.PostedFile.InputStream.Read(buffer, 0, iFile.PostedFile.ContentLength); return buffer; } return new byte[0]; }
0 0
- input type="file" 上传文件,若是flv格式,则截取保存一张图片asp.net
- input标签type="file"的格式要求,以及文件阅读,图片上传前的显示
- ASP.NET 使用Request.Files获取<input type=file/>上传文件
- asp.net/c# 用<input type="file" />实现文件上传,multipart/form-data
- asp.net/c# 用<input type="file" />实现文件上传,multipart/form-data
- Asp.net网站中 js通过input type="file" 上传文件
- html input控件type为file上传文件、图片,及保存为原文件
- input[type='file'] img图片上传
- 使用input type="file"上传文件
- input type=file 服务器端上传文件
- <input type="file"/> 文件上传
- html5 中input type=‘file’实现文件图片等的上传的文件类型限制
- 关于 input【type=file】文件上传控件实现自定义文字及实时图片预览
- html 实时显示input type=file 上传的图片
- Android WebView 支持H5图片上传<input type="file">
- input标签 type='file' 上传图片问题
- 使用input标签 type='file' 上传图片的问题
- [js实例] input type=file 上传图片预览 createObjectURL
- Go 性能优化技巧 5/10
- 显式游标和隐式游标的区别
- 安卓tabhost和子Activity通信方法
- Spingmvc中数据校验和异常处理详解
- 获取手机相关信息
- input type="file" 上传文件,若是flv格式,则截取保存一张图片asp.net
- 怎么解决Failed to load the JNIshared library
- 为什么有些人觉得项目经理类似于打杂的?怎么解释这种现象?
- XMG xib中不属于一个类的控件,拖线到指定的类中
- windows重装系统地址
- 欲写好一个类,必先将其解剖(类外定义)
- 布局
- 【转】提高MATLAB运行效率
- 软件概要设计做什么,怎么做