如何上传图片? [英] how can i upload image?
本文介绍了如何上传图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好先生/女士
我需要在asp .net中上传图像的编码.
解决方案
使用varbinary(Max)列存储图像
http://www. codeproject.com/answers/64080/如何上传和下载a-word-file-into-SQL-Se.aspx [ < = 文件 id = myFile runat = / myFile.PostedFile.SaveAs(" );
代码:
< html > ; < 头部 > < 脚本 语言 VB" runat >服务器" > 子上传(源为对象,e为EventArgs) 如果不是(myFile.PostedFile为空),则 将intFileNameLength变暗为Integer 昏暗的strFileNamePath作为字符串 昏暗的strFileNameOnly作为字符串 '查找文件名的逻辑(不包括路径) strFileNamePath = MyFile.PostedFile.FileName intFileNameLength = Instr(1,StrReverse(strFileNamePath),"\") strFileNameOnly =中(strFileNamePath,(Len(strFileNamePath)-intFileNameLength)+2) myFile.PostedFile.SaveAs("c:\ inetpub \ wwwroot \ yourwebapp \ upload \"& strFileNameOnly) lblMsg.Text =文件上传成功." 万一 结束子 < /script > < /head > < 正文 > < h3 > 文件上传< /h3 > < 表单 =" runat =" 服务器" > 文件:< 输入 id =" 类型 文件" runat 服务器" < asp:label id = lblMsg =" 服务器" / > < 输入 = 按钮 值 =" OnServerClick =" runat =" < /form > < /body > < /html >
if (imageUpload.PostedFile.ContentLength == true ; lblImage.Text = " ; 返回; } 字符串 strpath = Server.MapPath(" + imageUpload.FileName); imageUpload.SaveAs(strpath);
Hello Sir/Madam
I need the coding for uploading images in asp .net.
解决方案
use varbinary(Max) column to store image
http://www.codeproject.com/answers/64080/How-to-upload-and-download-a-word-file-into-SQL-Se.aspx[^]
First of all, we need a HTML server control to allow the user to select the file. This is nothing but the same old input tag, with the type set to File, such as<input type=file id=myFile runat=server />This will give you the textbox and a browse button. Once you have this, the user can select any file from their computer (or even from a network). Then, in the Server side, we need the following line to save the file to the Web Server.
myFile.PostedFile.SaveAs("DestinationPath");
Code:
<html> <head> <script language="VB" runat="server"> Sub Upload(Source As Object, e As EventArgs) If Not (myFile.PostedFile Is Nothing) Then Dim intFileNameLength as Integer Dim strFileNamePath as String Dim strFileNameOnly as String 'Logic to find the FileName (excluding the path) strFileNamePath = MyFile.PostedFile.FileName intFileNameLength = Instr(1, StrReverse(strFileNamePath), "\") strFileNameOnly = Mid(strFileNamePath, (Len(strFileNamePath)-intFileNameLength)+2) myFile.PostedFile.SaveAs("c:\inetpub\wwwroot\yourwebapp\upload\" & strFileNameOnly) lblMsg.Text = "File Upload Success." End If End Sub </script> </head> <body> <h3>File Upload</h3> <form enctype="multipart/form-data" runat="server"> File: <input id="myFile" type="file" runat="server"> <asp:label id=lblMsg runat="server" /> <input type=button value="Upload" OnServerClick="Upload" runat="server"> </form> </body> </html>
if (imageUpload.PostedFile.ContentLength == 0) { lblImage.Visible = true; lblImage.Text = "Please upload an Image"; return; } string strpath = Server.MapPath("Upload/" + imageUpload.FileName); imageUpload.SaveAs(strpath);
这篇关于如何上传图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文