读书人

求PB 兑现doc,xls,pdf文件上传到数据库

发布时间: 2013-03-26 09:54:34 作者: rapoo

求PB 实现doc,xls,pdf文件上传到数据库案例
求PB 实现DOC,XLS,PDF,JPG等文件上传到SQLSERVER保存,客户端实现上传和文件打开功能的案例
[解决办法]
//把二进制文件保存到数据库中的代码
SetPointer(HourGlass!)
// Get the file length, and open the file
flen = FileLength(ls_picname)
li_FileNum = FileOpen(ls_picname, &
StreamMode!, Read!, LockRead!)
if isnull(li_FileNum) or li_FileNum = -1 then
return 1
end if

// Determine how many times to call FileRead
IF flen > 32765 THEN
IF Mod(flen, 32765) = 0 THEN
loops = flen/32765
ELSE
loops = (flen/32765) + 1
END IF
ELSE
loops = 1
END IF
// Read the file
new_pos = 1
FOR i = 1 to loops
bytes_read = FileRead(li_FileNum, b)
if isnull( tot_b ) then
tot_b = b
else
tot_b = tot_b + b
end if
NEXT
FileClose(li_FileNum)

//update the row just inserted adding the blob ole control now
updateblob 表名
set 字段名 = :tot_b
where ………………………………;//此处条件省略

if SQLCA.SQLCode = -1 then
MessageBox("提示信息",SQLCA.SQLErrText,Information!)
return -1
end if

sqlca.autocommit = FALSE

////////////////////////////////////////////////////////////////////////////
//数据库中保存的二进制文件打开的代码
select 文件名
into :ls_picname
from 表名
where ......... //此处省略

ll_pos = pos( ls_picname , '\' )
if ll_pos > 0 then
ll_pos1 = ll_pos
end if

do while ll_pos > 0
ll_pos = pos( ls_picname , '\' , ll_pos + 1 )
if ll_pos > 0 then
ll_pos1 = ll_pos
end if
loop

ls_picname1 = right( ls_picname , len( ls_picname ) - ll_pos1 )

selectblob 二进制文件
into :ole_blob
from 表名
where ………………; //此处省略

if len( ole_blob ) = 0 then
return 1
end if

f_filewrite("c:\"+ ls_picname1, ole_blob)

ulong ll_hd = Handle(this) //for window event
String ls_operation , ls_parameters , ls_appdirectory , ls_filename
Long ll_result
constant long SW_RESTORE = 9
ls_Operation = "open"
ls_Parameters = ''

ls_filename = "c:\" + ls_picname1
ls_appDirectory = "c:\"

//查找指定文件关联在一起的程序文件名
ll_result = ShellExecute(ll_hd, ls_Operation, ls_filename, ls_Parameters, ls_appDirectory, SW_RESTORE) //通常是42




读书人网 >PB

热点推荐