Delphi 把客户端的文件或者目录上传到服务器端
来源:互联网 发布:淘宝网电影票团购 编辑:程序博客网 时间:2024/05/21 17:20
1、StringReplace字符串替换函数:
function StringReplace (const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;
rfReplaceAll:全部替换
rfIgnoreCase:忽略大小写
aStr := 'This is a book, not a pen!';
//This is two book, not a pen!只替换了第一个符合的字
StringReplace (aStr, 'a', 'two', []);
//This is two book, not two pen!替换了所有符合的字
StringReplace (aStr, 'a', 'two', [rfReplaceAll]);
aStr := 'This is a book, not A pen!';
//This is two book, not A pen!只替换了符合的字(小写a)
StringReplace (aStr, 'a', 'two', [rfReplaceAll]);
//This is two book, not two pen!不管大小写替换了所有符合的字
StringReplace (aStr, 'a', 'two', [rfReplaceAll, rfIgnoreCase]);
2、将客服端的ListBox中的文件或目录名称上传到服务器
//将上传文件列表中的文件或目录统一上传到服务器中对应的目录下
Procedure UpFile;
var
i:Integer;
begin
if CheckBox1.Checked then // 选择了上传文件
begin
if ListBox1.Count > 0 then // listBox1中存在文件需要上传
begin
for i := 0 to ListBox1.Count -1 do
begin
// 在磁盘上存在这样的文件
if FileExists(ListBox1.Items[i]) then
// 使用文件上传的方式上传文件
CopyFile(ExtractFilePath(ListBox1.Items[i]),ListBox1.Items[i])
Else
// 使用目录上传的方式上传文件
CopyFileDir(ExtractFilePath(ListBox1.Items[i]),ListBox1.Items[i]);
end;
end;
end;
end;
3、单个文件上传
Procedure CopyFile(ParentPath, Path: string);
var
vPath:string;
AllPath:string;
FileStream:TFileStream;
begin
if FileExists(Path) then
begin
// 等到文件的名称
vPath := StringReplace(Path,ParentPath,'\',[rfReplaceAll]);
// 设置文件存放的路径
AllPath := IntToStr(FYear) + '\' + IntToStr(FMonth) +
'\' + IntToStr(FDay) + '\' + IntToStr(FUserID) + vPath;
// 把要上传的文件存入流中
FileStream := TFileStream.Create(Path,fmOpenRead);
// 使用服务器端的上传函数上传文件到服务器。GetServer是返回一个远程数据服务类。
GetServer.UpFile(AllPath,StreamToVariant(FileStream));// 转换成变体的形式进行传递
FileStream.Free; // 切记
end
end;
4、目录上传
Procedure CopyFileDir(ParentPath:string;Path: string);
var
sr:TSearchRec;
fr:Integer;
AllPath:string;
vPath:string;
begin
if path[length(path)]<>'\' then
path := path + '\';
fr:=FindFirst(Path+'*.*',faAnyFile,sr);
while fr=0 do
begin
Application.ProcessMessages;
if (sr.Name<>'.')and(sr.Name<>'..') then
begin
if FileExists(Path + sr.Name) then
CopyFile(ParentPath,Path + sr.Name)
else
CopyFileDir(ParentPath,Path + sr.Name);
end;
fr := FindNext(sr);
end;
Windows.FindClose(fr);
end;
5、服务器端的上传函数;参数为文件路径、文件数据流。
Function UpFile(Path, Stream: OleVariant): OleVariant;
var
AllPath:string;
FileStream:TFileStream;
begin
Result := False;
AllPath := ExtractFilePath(Application.ExeName) + 'WorkLog\' + Path;
if not DirectoryExists(ExtractFilePath(AllPath)) then
ForceDirectories(ExtractFilePath(AllPath)); //创建多层目录.
if FileExists(AllPath) then
DeleteFile(AllPath);
FileStream := TFileStream.Create(AllPath,fmCreate or fmOpenReadWrite);
VariantToStream(Stream,FileStream); // 将变体类型的数据转换成二进制流
FileStream.Free;
Result := True;
end;
- Delphi 把客户端的文件或者目录上传到服务器端
- c#客户端图片上传到服务器端文件并且把路径保存到SQL数据库
- JAVA 服务器端的文件保存到客户端指定目录
- android客户端把SD卡文件上传到服务器端并保存在PC硬盘文件夹中
- 用struts上传文件时创建目录以及把文件上传到指定的目录
- ASP VB.NET 客户端上传文件到服务器端
- 使用TCP传输从客户端上传文件到服务器端
- android上传大文件到服务器客户端和服务器端代码
- 判断服务器端文件或者目录的存在性
- C#如何把Editor设计的内容上传到服务器端
- 客户端上传到服务端图片,服务端把图片保存到指定的文件中
- 客户端上传记事本到服务器端的指定的文件夹
- 文件或者图片上传到服务器端(tomcat),重启服务器或者重载项目之后上传文件或图片消失
- 多线程实现文件(图片)从客户端并行上传到服务器端--多客户端实现文件上传到服务器
- 基于TCP服务器端,客户端的上传任意文件Demo
- 客户端与服务器端的交互——上传文件
- HTML如何把文件上传到指定目录下
- 如何将服务器端文件 自动下载并保存到客户端IE临时文件夹 或者指定文件夹
- Delphi DBGrid中嵌套按钮
- oracle 分割字符串
- Delphi StringGrid常用属性和常用操作
- 获取 GPG 密钥失败:[Errno 14] 2011-05-26 14:43
- StringReplace字符串替换函数
- Delphi 把客户端的文件或者目录上传到服务器端
- Delphi 利用API实现网格内组件的嵌入
- ubuntu 10.04 dual monitor with xrandr
- java api doc
- 物联网云计算三网融合齐迎利好
- sicily 1623
- 提高自己的注意力,开始自己的人生
- 深入理解Android工程的编译过程
- Java 1.7的新特性