首页 > 问答大全 > asp二进制保存文件怎么打开

asp二进制保存文件怎么打开

2020-05-23 未知

asp如何将图片以二进方式存如数据库。非form方式

非form方式,

可以试试用ADODB.Stream这个组件,这是ADO默认安装的,大多

数ASP空间都支持的一个组件.该组件支持二进文件的读写操作,可以试试.

Set aso = CreateObject(“ADODB.Stream”)

aso.Mode = 3aso.Type = 1aso.Open

aso.LoadFromFile(“文件的本地路径”)

bstr = aso.Read(-1)

aso.Close

Set aso = Nothing

bstr 即为二进.

参照以下代码,例子是直接将图片存入数据

e799bee5baa6e78988e69d8331333264663731

库,路径存储可以仿照

protected void Button1_Click(object sender, EventArgs e)

{

if (DropDownList2.SelectedItem.Text.Trim() == “”)

{

Label1.Text = “提示:请选择图片类型!!”;

return;

}

if (FileUpload1.HasFile)

{

string fileContentType = FileUpload1.PostedFile.ContentType;

if (fileContentType == “image/bmp” || fileContentType == “image/gif” || fileContentType == “image/pjpeg”)

{

string name = FileUpload1.PostedFile.FileName; // 客户端文件路径

FileInfo file = new FileInfo(name);

string fileName = file.Name; // 文件名称

if (!File.Exists(webFilePath))

{

try

{

FileUpload1.SaveAs(webFilePath); // 使用 SaveAs 方法保存文件

OleDbConnection conn = new OleDbConnection();

conn.ConnectionString = “Provider=OraOLEDB.Oracle.1;Data Source=sdsfc;user id=shp;password=shp”;

conn.Open();

string cmd = “update shp.CMCS_SFC_IMEIPRINT_FUNCTION set PICTURE_NAME=:PICTURENAME,PICTURE=:PICTURE where BARCODE_TYPE='” + DropDownList2.SelectedItem.Text.Trim() + “‘”;

OleDbCommand sql = new OleDbCommand(cmd, conn);

HttpPostedFile UpFile = FileUpload1.PostedFile;

int FileLength = UpFile.ContentLength;

Byte[] FileByteArray = new byte[FileLength]; //图象文件临时储存Byte数组

Stream StreamObject = UpFile.InputStream;//建立数据流对像

StreamObject.Read(FileByteArray, 0, FileLength);//读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长

sql.Parameters.Add(“:PICTURENAME”, OleDbType.VarChar, 50).Value = fileName; //记录文件类型

sql.Parameters.Add(“:PICTURE”, OleDbType.LongVarBinary, FileLength).Value = FileByteArray;

sql.ExecuteNonQuery();

conn.Close();

Label1.Text = “提示:文件“” + fileName + “”成功上传”;

}

catch (Exception ex)

{

Label1.Text = “提示:文件上传失败,失败原因:” + ex.Message;

}

}

else

{

Label1.Text = “提示:文件已经存在,请重命名后上传”;

}

}

else

{

Label1.Text = “提示:文件类型不符”;

} } }

怎么用asp把一个地址的文件转换成二进啊

我想用ASP把一个如下的地址:上传代码

response.buffer=true

formsize=request.totalbytes

formdata=request.binaryread(formsize)

bncrlf=chrB(13) & chrB(10)

divider=leftB(formdata,clng(instrb(formdata,bncrlf))-1)

datastart=instrb(formdata,bncrlf & bncrlf)+4

dataend=instrb(datastart+1,formdata,divider)-datastart

mydata=midb(formdata,datastart,dataend)

set conn=server.createobject(“adodb.connection”)

connstr=”provider=microsoft.jet.oledb.4.0;data source=”&server.mappath(“db1.mdb”)

conn.open connstr

set rec=server.createobject(“ADODB.recordset”)

rec.Open “SELECT * FROM data where id is null”,conn,1,3

rec.addnew

rec(“data”).appendchunk mydata ‘/rec(“date”) 为数据库里面用存储数

e68a84e799bee5baa6e997aee7ad9431333231383930

据的字段 类行设置为:OLE对象

rec.update rec.close

set rec=nothing

set conn=nothing

‘——————————————————————–

打印图片代码

set conn=server.createobject(“adodb.connection”)

connstr=”provider=microsoft.jet.oledb.4.0;data source=”&server.mappath(“db1.mdb”)

conn.open connstr

set rs=server.createobject(“adodb.recordset”)

strsql=”select data from data where id=” & trim(request(“id”))

rs.open strsql,conn,1,1

if rs.eof then

response.write”“

else

response.contenttype = “image/*”

‘ 在输出到浏览器之前一定要指定response.contenttype = “image/*”,以便正常显示图片

response.binarywrite rs(“data”).getchunk(7500000)

rs.close

set rs=nothing

set conn=nothing

end if