第一、图片上传,代码如下:
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
代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < Request.Files.Count; i++)
{
HttpPostedFile file = Request.Files[i];
if (file.ContentLength > 0)
{
if (file.ContentType.Contains("image/"))
{
using (System.Drawing.Image img = System.Drawing.Image.FromStream(file.InputStream))
{
string FileName = System.IO.Path.GetFileName(file.FileName);
string[] SplitFileName = FileName.Split('.');
string AtterFileName = DateTime.Now.ToString("yyyMMddHHmmss")+"." + SplitFileName[1];
img.Save(Server.MapPath("/upload/" + AtterFileName));
新闻热点
疑难解答
图片精选