Access开发平台--上传下载函数,实现通用附件支持FTP。
时 间:2019-04-17 00:52:35
作 者:丘苏洲 ID:66601 城市:普宁
摘 要:开发平台上传下载函数,实现通用附件支持FTP。
正 文:
Access快速开发平台通用附件的图片用共享文件夹的方式,安全性能不高,可能存在误删除。把图片文件用FTP的方法保存,在客户端开通FTP即可实现通用附件的FTP网络服务器实时共享。
优点是括大了服务器的应用范围,缺点是每次浏览都要重新下载更新图片文件,性能不如共享。
一、企业版:设置开发平台FTP:
专业版在系统表 Sys_ServerParameters 手工增加以下内容即可。
二、复制上传,下载自定义函数代码到“模块”
三、在 通用附件窗体(SysFrmAttachments) 下新增红字调用函数代码:
代码所在位置请自行对应。
四、架设FTP服务器方法请自行查找。
1、保存事件
Public Function SaveAttachmentData(DataCategory As String _
, DataID As Variant _
, Optional ActiveConnection As Variant _
)
‘中间部分省略
rst![AttachmentName] = rstTmp![AttachmentName]
uploadFTPfile rstTmp![AttachmentName] '上传到FTP
rst.Update
‘中间部分省略
2、加载浏览事件
Public Function LoadAttachmentData(DataCategory As String _
, DataID As Variant _
, Optional ActiveConnection As Variant _
)
‘中间部分省略
rstTmp![AttachmentName] = rst![AttachmentName]
downloadFTPfile rst![AttachmentName] '下载FTP到本地
rstTmp.Update
‘中间部分省略
附上传及下载函数:
Function downloadFTPfile(downFILEname As String) As Boolean
On Error GoTo ErrorHandler
'下载 FTP 文件
If getParameter("FTP Server Address", dbText, "", , , True) = "" Then GoTo ExitHere
Dim AttPATH As String
'本地保存路径设置
AttPATH = getParameter("Attachment Path", dbText, "", , , True)
If Len(AttPATH) = 0 Then AttPATH = CurrentProject.Path & "\Attachments\"
If Left(AttPATH, 2) = ".\" Then AttPATH = CurrentProject.Path & Mid(AttPATH, 2)
If Right(AttPATH, 1) <> "\" Then AttPATH = AttPATH & "\"
If dir(AttPATH)="" then mkdir(AttPATH)
With FTPServer
.OpenConnection ‘专业版需直接使用参数 getParameter("FTP Server Address", dbText, "", , , True),getParameter("FTP Server Port", dbText, "", , , True),getParameter("FTP Server Username", dbText, "", , , True),getParameter("FTP Server Password", dbText, "", , , True)
If .FileExists("Attachments\" & downFILEname) Then .DownloadFile "Attachments\" & downFILEname, AttPATH & downFILEname
.CloseConnection
End With
ExitHere:
downloadFTPfile = True
Exit Function
ErrorHandler:
downloadFTPfile = False
End Function
Function uploadFTPfile(upFILEname As String) As Boolean
On Error GoTo ErrorHandler
'上传 FTP 文件
If getParameter("FTP Server Address", dbText, "", , , True) = "" Then GoTo ExitHere
Dim AttPATH As String
'本地保存路径设置
AttPATH = getParameter("Attachment Path", dbText, "", , , True)
If Len(AttPATH) = 0 Then AttPATH = CurrentProject.Path & "\Attachments\"
If Left(AttPATH, 2) = ".\" Then AttPATH = CurrentProject.Path & Mid(AttPATH, 2)
If Right(AttPATH, 1) <> "\" Then AttPATH = AttPATH & "\"
With FTPServer
.OpenConnection ‘专业版需直接使用参数 getParameter("FTP Server Address", dbText, "", , , True),getParameter("FTP Server Port", dbText, "", , , True),getParameter("FTP Server Username", dbText, "", , , True),getParameter("FTP Server Password", dbText, "", , , True)
'判断FTP是否存在Attachments文件夹
If .FileExists("Attachments") = False Then .CreateDirectory "Attachments"
If Dir(AttPATH & upFILEname) <> "" Then .UploadFile AttPATH & upFILEname, "Attachments\" & upFILEname
.CloseConnection
End With
ExitHere:
uploadFTPfile = True
Exit Function
ErrorHandler:
uploadFTPfile = False
End Function
Access快速开发平台QQ群 (群号:321554481) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 统计当月之前(不含当月)的记录...(03.11)
- 【Access Inputbo...(03.03)
- 按回车键后光标移动到下一条记录...(02.12)
- 【Access Dsum示例】...(02.07)
- Access对子窗体的数据进行...(02.05)
- 【Access高效办公】上月累...(01.09)
- 【Access高效办公】上月累...(01.06)
- 【Access Inputbo...(12.23)
- 【Access Dsum示例】...(12.16)

学习心得
最新文章
- 仓库管理实战课程(9)-开发往来单...(04.02)
- 仓库管理实战课程(8)-商品信息功...(04.01)
- 仓库管理实战课程(7)-链接表(03.31)
- 仓库管理实战课程(6)-创建查询(03.29)
- 仓库管理实战课程(5)-字段属性(03.27)
- 设备装配出入库管理系统;基于Acc...(03.24)
- 仓库管理实战课程(4)-建表操作(03.22)
- 仓库管理实战课程(3)-需求设计说...(03.19)
- 仓库管理实战课程(2)-软件背景和...(03.18)
- 仓库管理实战课程(1)-讲师介绍(03.16)