日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 芯聞號 > 充電吧
[導讀]? 注意:上傳大文件時,會出現(xiàn)錯誤,原因我現(xiàn)在還不知道. 數(shù)據(jù)庫名:mydata 表名:table_img 字段:id?? 自動編號 filename?? 文本 img???? OLE 對象 ? d

?<
??


???

?????

???????

???????

?????
???


?

?

default.aspx.cs

using System;
using System.Data;
using System.Configuration;
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;
using System.Data.OleDb;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
??? protected void Page_Load(object sender, EventArgs e)
??? {

??? }

??? protected void Button1_Click(object sender, EventArgs e)
??? {
??????? try
??????? {
??????????? if (FileUpload1.HasFile)
??????????? {
??????????????? if (IsAllowedExtension(this.FileUpload1))
??????????????? {
??????????????????? //取得上傳文件的大小
??????????????????? int FileLen = FileUpload1.PostedFile.ContentLength;

??????????????????? Byte[] FileData = new Byte[FileLen];

??????????????????? //創(chuàng)建訪問客戶端上傳文件的對象
??????????????????? HttpPostedFile hp = FileUpload1.PostedFile;

??????????????????? //創(chuàng)建數(shù)據(jù)流對象
??????????????????? Stream sr = hp.InputStream;

??????????????????? //將圖片數(shù)據(jù)放到FileData數(shù)組對象實例中,0代表數(shù)組指針的起始位置,FileLen代表指針的結束位置
??????????????????? sr.Read(FileData, 0, FileLen);
??????????????????? string strdatapath = "Provider = Microsoft.JET.OleDB.4.0;Data Source = " + Server.MapPath("mydata.mdb");
??????????????????? OleDbConnection conn = new OleDbConnection(strdatapath);
??????????????????? conn.Open();
??????????????????? OleDbCommand cmd = new OleDbCommand("insert into table_img(filename,img) values(filename,img)", conn);

??????????????????? //存儲過程插入到數(shù)據(jù)庫中
??????????????????? OleDbParameter para1 = new OleDbParameter("filename", OleDbType.VarChar);
??????????????????? para1.Value = "FileData";
??????????????????? cmd.Parameters.Add(para1);
??????????????????? //存儲過程插入到數(shù)據(jù)庫中
??????????????????? OleDbParameter para = new OleDbParameter("img", OleDbType.Binary);
??????????????????? para.Value = FileData;
??????????????????? cmd.Parameters.Add(para);
??????????????????? cmd.ExecuteNonQuery();

??????????????????? //彈出上傳成功的提示
??????????????????? Response.Write("");
????????????????? //? Response.Write("");

??????????????????? //關閉數(shù)據(jù)庫連接
??????????????????? conn.Close();

??????????????? }
??????????????? else
??????????????? {
??????????????????? Response.Write("");
????????????????? //? Response.Write("");
??????????????? }
??????????? }
??????????? else
??????????? {
??????????????? Response.Write("");
?????????????? // Response.Write("");
??????????? }
??????? }
??????? catch (Exception ex)
??????? {
????????????? Response.Write(ex.Message);
??????????? throw new Exception(ex.Message + "數(shù)據(jù)庫連接失敗");
??????? }


??? }

??? #region 實現(xiàn)真正意義上的文件類型判斷
??? public static bool IsAllowedExtension(FileUpload hifile)
??? {
??????? System.IO.FileStream fs = new System.IO.FileStream(hifile.PostedFile.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
??????? System.IO.BinaryReader r = new System.IO.BinaryReader(fs);
??????? string fileclass = "";
??????? byte buffer;
??????? try
??????? {
??????????? buffer = r.ReadByte();
??????????? fileclass = buffer.ToString();
??????????? buffer = r.ReadByte();
??????????? fileclass += buffer.ToString();

??????? }
??????? catch
??????? {
??????? }
??????? r.Close();
??????? fs.Close();
??????? if (fileclass == "255216" || fileclass == "7173")//說明255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar
??????? {
??????????? return true;
??????? }
??????? else
??????? {
??????????? return false;
??????? }
??? }
??? #endregion

}

?

?

?

顯示圖片

?protected void Button2_Click(object sender, EventArgs e)
??? {
??????? // 在此處放置用戶代碼以初始化頁面

??????? show();? //顯示圖片

??? }
??? public void show()
??? {
??????? string strdatapath = "Provider = Microsoft.JET.OleDB.4.0;Data Source = " + Server.MapPath("mydata.mdb");
??????? OleDbConnection conn = new OleDbConnection(strdatapath);
?????? // conn.Open();
??????? string ss = "1";// Request.QueryString["id"].ToString();
??????? string s3 = "select * from table_img? where id=" + ss;
??????? OleDbCommand comm = new OleDbCommand(s3, conn);
??????? conn.Open();
??????? OleDbDataReader dr = comm.ExecuteReader(CommandBehavior.CloseConnection);
??????? while (dr.Read())
??????? {
??????????? Response.Clear();
????????? //? Response.C;
??????????? Response.BinaryWrite((byte[])dr["img"]);//讀取
??????? }
??????? Response.End();
??????? conn.Close();
??? }

本站聲明: 本文章由作者或相關機構授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關閉