写一个80服务,实现在浏览器输入IP地址/文件名,就可以下载该文件。如输入:http://192.168.0.100/test.txt,就可以把test.txt这个文件下载到本地。我现在用idtcpserver组件可以接到浏览器的请求,但是想传文件就会卡在那不动?procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
iFileHandle:integer;
iFileLen,cnt,ASize:integer;
buf:array[0..4096] of byte;
str,str1:string;
begin
with ATHread.Connection do
begin
str1:=UpperCase(ReadLn);
memo1.Lines.Add(str1);
str:='E:\test.txt;
iFileHandle:=FileOpen(str,fmOpenRead); iFileLen:=FileSeek(iFileHandle,0,2);
// showmessage(inttostr(ifilelen));
FileSeek(iFileHandle,0,0);
writeinteger(iFileLen);
while true do
begin
Application.ProcessMessages;
cnt:=FileRead(iFileHandle,buf,4096);
writeBuffer(buf,cnt);
if cnt<4096 then
break;
end;
FileClose(iFileHandle);
label1.Caption:='文件传送完毕';
end;end;
请高手指点,感谢
var
iFileHandle:integer;
iFileLen,cnt,ASize:integer;
buf:array[0..4096] of byte;
str,str1:string;
begin
with ATHread.Connection do
begin
str1:=UpperCase(ReadLn);
memo1.Lines.Add(str1);
str:='E:\test.txt;
iFileHandle:=FileOpen(str,fmOpenRead); iFileLen:=FileSeek(iFileHandle,0,2);
// showmessage(inttostr(ifilelen));
FileSeek(iFileHandle,0,0);
writeinteger(iFileLen);
while true do
begin
Application.ProcessMessages;
cnt:=FileRead(iFileHandle,buf,4096);
writeBuffer(buf,cnt);
if cnt<4096 then
break;
end;
FileClose(iFileHandle);
label1.Caption:='文件传送完毕';
end;end;
请高手指点,感谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货