求asp.net(c#)图片上传源码
图片以单独文件夹保存.越简单越好.谢谢各位了. --------------------编程问答-------------------- protected void Button1_Click(object sender, EventArgs e){
string a=FileUpload1.PostedFile.FileName;
int i = a.LastIndexOf('.');
string ex = a.Substring(i, a.Length - i);
Random r=new Random();
string filename = DateTime.Now.Ticks + r.Next().ToString();
FileUpload1.PostedFile.SaveAs(Server.MapPath("upload/" + filename + ex));
}
拖个uploadfile控件,在拖个button 把上面的代码写进去,ok了 --------------------编程问答-------------------- 同意!~~ --------------------编程问答-------------------- 在USER.ASPX上有一个textbox1.如何得到刚上传图片的路径?. --------------------编程问答-------------------- 你得到本地路径不就行了? --------------------编程问答-------------------- 就是把上传的图片路径写入数据库写呢.还有就是uploadfile控件怎么在VS2003没有.?求jiao545214147再帮帮我.谢谢 --------------------编程问答-------------------- sorry我打错了
是FileUpload --------------------编程问答-------------------- 你保存到数据库里面的话,
路径是当前页
FileUpload1.PostedFile.SaveAs(Server.MapPath("upload/" + filename + ex));
upload+你的文件名保存到数据库就行了 --------------------编程问答-------------------- FileUpload 也没有.只有file field. --------------------编程问答-------------------- mark --------------------编程问答-------------------- file field
就是这个啊
--------------------编程问答-------------------- 好.谢谢各位朋友,新年快乐 --------------------编程问答-------------------- 谢谢 --------------------编程问答-------------------- 干吗不结贴 啊 --------------------编程问答-------------------- .C部分
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class fileupload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string Name = FileUpload1.FileName;//获取已上传文件的名字
string Size = FileUpload1.PostedFile.ContentLength.ToString();//获取已经上传文件的大小
string Type = FileUpload1.PostedFile.ContentType;//获取上传文件的类型
string Type1 = Name.Substring(Name.LastIndexOf(".") + 1);//这是从上传控件里得到的文件的后缀
string Ipath = Server.MapPath("Upfile") + "\\" + Name;
string Wpath = "Upfile\\"+Name;
if (Type1 == "jpg" || Type1 == "swf" || Type1 == "gif" || Type1 == "bmp" || Type1 == "png" || Type1 == "JPG")
{
FileUpload1.SaveAs(Ipath);
Image1.ImageUrl = Wpath;
Label1.Text = "您上传的文件名称是" + Name + "<br>文件大小为" + Size + "字节<br>文件类型是" + Type;
}
else
{
Response.Write("<script language=javascript>");
Response.Write("alert('该文件不允许上传!');");
Response.Write("</script>");
}
}
}
aspx文件部分
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="fileupload.aspx.cs" Inherits="fileupload" %>
<!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>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" Style="position: relative" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="position: relative"
Text="Button" /><br />
<asp:Image ID="Image1" runat="server" Style="position: relative" /><br />
<asp:Label ID="Label1" runat="server" Style="position: relative" Text="Label"></asp:Label></div>
</form>
</body>
</html> --------------------编程问答-------------------- 你这个上传能防止注入漏洞吗
比如吧asp木马程序改成jpeg的后缀上传,能防止吗 --------------------编程问答-------------------- mark --------------------编程问答-------------------- 又是要代码的,还是这样的代码 --------------------编程问答-------------------- 07年的帖子居然都被翻出来了 --------------------编程问答-------------------- 关注呀
--------------------编程问答-------------------- 我是11年的未来人,楼上的都还活着吧... --------------------编程问答--------------------
僵尸贴子又出来吓人了,好恐怖哦。 --------------------编程问答-------------------- 将盗墓进行到底....
补充:.NET技术 , ASP.NET