procedure TWebModule_UP.WebModule1WebActionItem_UpAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
const
BuffSize = 32 * 1024;
var
i, FilebeginIdx, NowFileSize, FileSize, B, S, j, HeadEndIdx, FileEndIdx: integer;
strFileName: string;
Fs: TFileStream;
BytesRead, nowRead: integer;
Head, Buffer: string;
sDelimiter: string;
path: string;
input_code, uP: string;
sl: TStringList;
procedure checkHead;
var
B1, b2: integer;
s: string;
begin
if FilebeginIdx < 1 then
begin
if HeadEndIdx < 1 then
begin
B1 := pos(#13#10#13#10, Buffer);
if b1 >= 0 then
begin
s := copy(Buffer, B1 + 4, 1024 * 2);
b2 := pos(#13#10#13#10, s);
if b2 > 0 then
HeadEndIdx := b1 + b2 + 3;
end;
end;
if HeadEndIdx > 0 then
begin
FilebeginIdx := HeadEndIdx + 4;
Head := copy(Buffer, 1, HeadEndIdx - 1);
b1 := pos('name="input_code"', Head);
s := trim(copy(Head, b1 + length('name="input_code"'), 255));
b1 := pos(#13#10, s);
if b1 > 0 then
input_code := trim(copy(s, 1, b1));
j := pos(#13#10, Head);
sDelimiter := copy(Head, 1, j - 1);
FileEndIdx := FileEndIdx - (145 - 2 * 43) - 2 * length(sDelimiter);
FileSize := FileEndIdx - FilebeginIdx + 1;
j := Pos('filename="', Head);
if j > 0 then
begin
strFileName := Copy(Head, j + 10, MaxInt);
strFileName := ExtractFileName(Copy(strFileName, 1, Pos('"', strFileName) - 1));
strFileName := StringReplace(strFileName, ' ', '', [rfReplaceAll]);
path := ExtractFilePath(Request.TranslateURI(Request.URL)) + 'File/' + input_code + '/';
if not DirectoryExists(path) then
begin
ForceDirectories(path);
end;
strFileName := path + strFileName;
fs := TFileStream.Create(strFileName, fmShareDenyNone or fmCreate);
end
else
;
end;
end;
end;
procedure w;
begin
if FilebeginIdx > 0 then
begin
if FilebeginIdx > BytesRead then
B := FilebeginIdx
else
B := 1;
S := nowRead - b + 1;
if s + NowFileSize > FileSize then
s := FileSize - NowFileSize;
if strFileName <> '' then
fs.Write(Buffer, S);
NowFileSize := NowFileSize + s;
end;
end;
begin
try
inc(AccessCount);
Response.ContentType := 'text/html';
try
FilebeginIdx := 0;
BytesRead := 0;
HeadEndIdx := 0;
NowFileSize := 0;
strFileName := '';
FileEndIdx := Request.ContentLength;
FileSize := 0;
{sl := TStringList.Create;
sl.Text := Request.Content;
sl.SaveToFile('d:/1.txt');
FreeAndNil(sl); }
Buffer := Request.Content;
nowRead := length(Buffer);
checkHead;
w;
BytesRead := nowRead;
if FileSize > NowFileSize then
begin
setlength(Buffer, BuffSize);
try
repeat
nowRead := FileSize - NowFileSize;
if nowRead > BuffSize then
nowRead := BuffSize;
nowRead := Request.ReadClient(Buffer[1], BuffSize);
checkHead;
if nowRead > 0 then
w;
BytesRead := BytesRead + nowRead;
until
(nowRead <= 0) or (NowFileSize >= FileSize);
except
;
end;
end;
Buffer := '';
if strFileName <> '' then
try
freeandnil(fs);
except;
end;
uP := lastD(Request.URL);
if strFileName <> '' then
uP := uP + '/up_suc.asp'
else
uP := uP + '/up_error.asp';
Response.SendRedirect(uP);
except
on E: Exception do
begin
uP := lastD(Request.URL);
uP := uP + '/up_error.asp';
Response.SendRedirect(uP);
end;
end;
Buffer := '';
except
on E: Exception do recordEvent('up ' + strFileName + ' ' + E.Message);
end;
end;