<? //上载文件
function UploadFile($srcName,$Size,$destName,$destPath)
{
echo $srcName."<hr>";
echo $destPath.$destName."<hr>";
if (!is_uploaded_file($srcName)) {
$Result['result']="FAILDED";
$Result['info']="the file is not a upload file !";
return $Result;
}
//检查参数的合法性
if (!is_dir($destPath)){
if (!mkdir($destPath,0777)){
$Result['result']="FAILDED";
$Result['info']="the destination directory is not exist!";
return $Result;
}
}
if ( 1024000 < $Size ){
$Result['result']="FAILDED";
$Result['info']="file is must be less than 1 MB(1024000 Bytes)!";
return $Result;
}
if ("" == $destPath){
$Result['result']="FAILDED";
$Result['info']="The destination of path is invalid!";
return $Result;
}
//输入了上载文件,但文件未上载成功
if ( ($srcName == "none" || $srcName == "" ) and $destName!=""){
$Result['result']="FAILDED";
$Result['info']="The file <font color=red>".$destName."</font> 's uploaded failed !";
return $Result;
}
//未输入上载文件
if (($srcName == "none" || $srcName == "" ) and $destName==""){
$Result['result']="FAILDED";
$Result['info']="no uploaded file!";
return $Result;
}
//文件重名处理
$i = 1;
while (file_exists($destPath.$destName)){
$destName = "$i".$destName;
$i++;
}
//文件上载成功后,将文件拷贝到目的地
if (!move_uploaded_file($srcName,$destPath.$destName)){
$Result['result']="FAILDED";
$Result['info']="the file <font color=red>".$destName."</font>'s uploaded failed!";
return $Result;
} //返回成功信息
$Result['result']='SUCCESS';
$Result['info']=$destName;
echo $destName;
return $Result;
}
?>
<? //上载文件
function UploadFile($srcName,$Size,$destName,$destPath)
{
echo $srcName."<hr>";
echo $destPath.$destName."<hr>";
if (!is_uploaded_file($srcName)) {
$Result['result']="FAILDED";
$Result['info']="the file is not a upload file !";
return $Result;
}
//检查参数的合法性
if (!is_dir($destPath)){
if (!mkdir($destPath,0777)){
$Result['result']="FAILDED";
$Result['info']="the destination directory is not exist!";
return $Result;
}
}
if ( 1024000 < $Size ){
$Result['result']="FAILDED";
$Result['info']="file is must be less than 1 MB(1024000 Bytes)!";
return $Result;
}
if ("" == $destPath){
$Result['result']="FAILDED";
$Result['info']="The destination of path is invalid!";
return $Result;
}
//输入了上载文件,但文件未上载成功
if ( ($srcName == "none" || $srcName == "" ) and $destName!=""){
$Result['result']="FAILDED";
$Result['info']="The file <font color=red>".$destName."</font> 's uploaded failed !";
return $Result;
}
//未输入上载文件
if (($srcName == "none" || $srcName == "" ) and $destName==""){
$Result['result']="FAILDED";
$Result['info']="no uploaded file!";
return $Result;
}
//文件重名处理
$i = 1;
while (file_exists($destPath.$destName)){
$destName = "$i".$destName;
$i++;
}
//文件上载成功后,将文件拷贝到目的地
if (!move_uploaded_file($srcName,$destPath.$destName)){
$Result['result']="FAILDED";
$Result['info']="the file <font color=red>".$destName."</font>'s uploaded failed!";
return $Result;
} //返回成功信息
$Result['result']='SUCCESS';
$Result['info']=$destName;
echo $destName;
return $Result;
}
?>
推荐phpbb
'
' 用ASP实现无组件上传/下载文件
'
' 功能简介
' 将上传的文件数据保存到数据库中,可以处理表单中的多个上传文件的情况
' 适用于各种数据库,使用ADO的方法连接数据库
' 本示例中使用的是ACCESS数据库:zj.mdb
' 表:tb_img(id int(自增列),path text(255) 保存上传文件的目录
' ,fname text(250) 保存上传的文件名,img ole对象 保存上传的文件内容
' ,type text(250) 保存上传的文件类型
'
' 邹建 2003.10
'==================================================================
'==================================================================
'
' 上传文件的HTML页: zj_up.htm
'
'==================================================================
<html>
<head>
<title>文件上传保存到数据库中</title>
</head>
<body>
<form name="form1" enctype="multipart/form-data" method="post" action="zj_up.asp">
<p>
<input type="file" name="file">
<input type="submit" name="Submit" value="上传">
</p>
</form>
</body>
</html>
'==================================================================
'
' 上传文件保存到数据库的ASP页: zj_up.asp
'
'==================================================================
<%
Response.Expires=0
Function f_Bin2Str(ByVal sBin)
Dim iI, iLen, iChr, iRe
iRe = ""
If Not IsNull(sBin) Then
iLen = LenB(sBin)
For iI = 1 To iLen
iChr = MidB(sBin, iI, 1)
If AscB(iChr) > 127 Then
iRe = iRe & Chr(AscW(MidB(sBin, iI + 1, 1) & iChr))
iI = iI + 1
Else
iRe = iRe & Chr(AscB(iChr))
End If
Next
End If
f_Bin2Str = iRe
End Function
iConcStr = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False" & _
";Data Source=" & server.mappath("zj.mdb")
iSql="tb_img"
set iRe=Server.CreateObject("ADODB.Recordset")
iRe.Open iSql,iConcStr,1,3
iLen=Request.TotalBytes
sBin=Request.BinaryRead(iLen)
iCrlf1 = ChrB(13) & ChrB(10)
iCrlf2 = iCrlf1 & iCrlf1
iLen = InStrB(1, sBin, iCrlf1) - 1
iSpc = LeftB(sBin, iLen)
sBin = MidB(sBin, iLen + 34)
iPos1 = InStrB(sBin, iCrlf2) - 1
While iPos1 > 0
iStr = f_Bin2Str(LeftB(sBin, iPos1))
iPos1 = iPos1 + 5
iPos2 = InStrB(iPos1, sBin, iSpc)
iPos3 = InStr(iStr, "; filename=""") + 12
If iPos3 > 12 Then
iStr = Mid(iStr, iPos3)
iPos3 = InStr(iStr, Chr(13) & Chr(10) & "Content-Type: ") - 2
iFn = Left(iStr, iPos3)
If iFn <> "" Then
iRe.AddNew
ire("path")=left(iFn,instrrev(iFn,"\"))
iRe("fname") = mid(iFn,instrrev(iFn,"\")+1)
iRe("type") = Mid(iStr, iPos3 + 18)
iRe("img").AppendChunk MidB(sBin, iPos1, iPos2 - iPos1)
iRe.Update
End If
End If
sBin = MidB(sBin, iPos2 + iLen + 34)
iPos1 = InStrB(sBin, iCrlf2) - 1
Wend
iRe.close
set iRe=Nothing
%>'==================================================================
'
' 下载数据的ASP页: zj_down.asp
'
'==================================================================
<%
Response.Buffer=true
Response.CleariConcStr = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False" & _
";Data Source=" & server.mappath("zj.mdb")
set iRe=server.createobject("adodb.recordset")
iSql="tb_img"
iRe.open iSql,iconcstr,1,1
Response.ContentType=ire("type")
Response.BinaryWrite iRe("img")iRe.close
set iRe=Nothing
%>
a.html
_____________________________________________
<img src="show.asp?id=1">小弟搞了一个简单的操作员管理系统,操作员表中,除了存储基本的操作员Id,pwd,name等信息外,还有个存操作员头像的picture字段,类型为image我在窗体上放了一个Image控件,我要实现一下功能,insert into operator (picture) values (Image->Picture) where Id = ?select picture字段 from operator where Id=?update operator set picture=Image->Picture where Id=?顺便说一下,我在Csdn里面看了很多关于存储图片的类子,可是这两天怎么都没搞定,
希望各位大侠再帮忙了,100分相送。对了,贴段代码了,让各位看看错再哪里? ADOConnection1->Open();
if(OpenPictureDialog1->Execute())
{
ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add("insert into tablll(opPhoto) values (:BlobField)");
TBlobField *Field = (TBlobField*)ADOQuery1->FieldByName("opPhoto");
ADOQuery1->Parameters->ParamByName("BlobField")->Value=Field; Field->LoadFromFile(OpenPictureDialog1->FileName);
ADOQuery1->ExecSQL(); 用image类型 建立下面这个存储过程
--------------------------------------------------
CREATE PROCEDURE sp_textcopy
@srvname varchar (30),
@login varchar (30),
@password varchar (30),
@dbname varchar (30),
@tbname varchar (30),
@colname varchar (30),
@filename varchar (30),
@whereclause varchar (40),
@direction char(1)
AS
/* 这是使用textcopy工具将文件插入到数据库中,如果有前台工具可以用前台开发工具将文件插入,这里为了演示 */
DECLARE @exec_str varchar (255)
SELECT @exec_str='textcopy /S '+@srvname+' /U '+@login+' /P '+@password+' /D '+@dbname+' /T'+@tbname+' /C '+@colname+' /W"'+@whereclause+'" /F"'+@filename+'" /'+@direction
EXEC master..xp_cmdshell @exec_str
----------------------------------------------------insert dali values(1,0x,'doc','大力的doc') ---其中第二列是 0x 它是一个16进制数对应image列,是必须的,不要写null,第三列是文件类型,既扩展名sp_textcopy '你的服务器名','sa','你的密码','test','dali','MyImage','c:\大力的doc.doc','where ID=1','I'
-------依次参数是:实例名,用户名,密码,数据库名,表名,image列名,路径及文件名,条件(你必须保证它只选择一行),I
---------------------------------------------------------------------------------------------------------------------
insert dali values(2,0x,'bmp','图片')
sp_textcopy '你的服务器名','sa','你的密码','test','dali','MyImage','c:\图片.bmp','where ID=2','I' --注意条件是 ID=2insert dali values(3,0x,'xls','Excel文件')
sp_textcopy '你的服务器名','sa','你的密码','test','dali','MyImage','c:\Excel文件.xls','where ID=3','I' --注意条件是 ID=3insert dali values(4,0x,'htm','网页')
sp_textcopy '你的服务器名','sa','你的密码','test','dali','MyImage','c:\网页.htm','where ID=4','I' --注意条件是 ID=4----------上面的语句,要保证类型一样,路径正确,条件唯一正确应该就可以了
http://www.51one.net/soft/1216.htm
有中文版的,下载一个安装试试~!:)