using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class upload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btupload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string filecontentType = FileUpload1.PostedFile.ContentType;
if (filecontentType == "image/bmp" || filecontentType == "image/gif" || filecontentType == "image/pjpeg" || filecontentType == "image/jpeg")
{
string name = FileUpload1.PostedFile.FileName;
FileInfo file= new FileInfo(name);
string filename = file.Name;
string webFilePath = Server.MapPath("image/" + filename);
if (!File.Exists(webFilePath))
{
try
{
FileUpload1.SaveAs(webFilePath);
this.lmsg.Text = "提示:文件" + filename + "上傳成功!";
this.lpathInfo.Text = "image/" + filename;
this.iPic.ImageUrl = "image/" + filename;
}
catch (Exception ex)
{
this.lmsg.Text = "提示文件上傳失敗,失敗原因" + ex.Message;
}
}
else
{
this.lmsg.Text = "該文件已經(jīng)存在!";
}
}
else {
this.lmsg.Text = "提示:文件類型不符";
}
}
}
}
前臺代碼如下:文件下載代碼
分享題目:文件上傳后臺和前臺代碼(文件下載也是)-創(chuàng)新互聯(lián)
地址分享:http://jinyejixie.com/article0/cspeio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、搜索引擎優(yōu)化、手機(jī)網(wǎng)站建設(shè)、網(wǎng)站收錄、微信公眾號、品牌網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容