Active server object에서요
ENCTYPE="multipart/form-data"형으로 올린 자료를
Request->Binaryread(AoleVariant,contentData)로 읽어드려서요
string변수나 AnsiString변수에 옳겨야 하는데 contentdata에 들어
있는 데이타형이 바이너리값이라는게 문제입니디다
옳겨오면서 데이타손실이 나는건지 아니면 pos함수가 안 먹는건지
감이 안 옵니다.
저는 a=AnsiString(contentdata.operator AnsiString())함수를 썼는데요
Reponse->Write((Varian(a));시 앞에 형만 보이고 파일바이너리 부분은
안보압니다.
Response->BinaryWrite((Variant(a));의경우 데이타양은 맞는것같은데
깨진 글자구요
아시는 고수님들 Variant형에 들어있는 바이너리값을 그대로 String or
AnsiString으로 가져오는 방법없나요?
답답한 마음에 이렇게 delphi소스까지 올려놓습니다.
아시는 분께서는 도움 좀 주십시오 ^^
파일올리기
<
>
<
유저쪽에서 서버쪽에 전송해온 양식은 다음과 같습니다:
-----------------------------7cf1d6c47c#13#10
Content-Disposition: form-data; name="SaveAs"#13#10#13#10
NewFileName#13#10
-----------------------------7cf1d6c47c#13#10
Content-Disposition: form-data; name="FileData"; filename="D:\test.txt"
Content-Type: text/plain#13#10#13#10
text안에내용은 여기。#13#10
-----------------------------7cf1d6c47c#13#10
Content-Disposition: form-data; name="b1"#13#10#13#10
확인#13#10
-----------------------------7cf1d6c47c--
“-----------------------------7cf1d6c47c”form간의 경계선
#13#10是回车换行符的DELPHI表示(번역이 안돼네^^
private
FContentLength : LongInt;
FContentData : Variant;
FFileName,
FDelimeter : string;
FScriptingContext : IScriptingContext;
FFileDataStart,
FFileDataEnd : LongInt;
procedure TUploadFile.OnStartPage(AScriptingContext: IUnknown);
var
ARequest : IRequest;
AOleVariant : OleVariant;
intDelimterLength : integer;
longIndex,ALongInt,longPos : LongInt;
ContentData : AnsiString;
strTemp : string;
FindEndOfFileData : boolean;
begin
ScriptingContext := AScriptingContext as IScriptingContext;
ARequest := FScriptingContext.Request;
FContentLength := ARequest.TotalBytes;
FContentData := VarArrayCreate( [0,FContentLength], varByte );
AOleVariant := FContentLength;
FContentData := ARequest.BinaryRead( AOleVariant );
ContentData := '';
for longIndex := 0 to FContentLength - 1 do
begin
ContentData := ContentData + chr( Byte( FContentData[ longIndex ] ));
if FContentData[ longIndex ] = 0 then break;
end;
longPos := pos( #13#10,ContentData );
FDelimeter := Copy( ContentData,1,longPos-1);
strTemp := 'filename="';
longPos := pos( strTemp, ContentData );
if longPos <= 0 then
begin
FFileName := '';
FFileDataStart := -1;
FFileDataEnd := -2;
exit;
end;
longPos := longPos + length( strTemp );
strTemp := '';
for longIndex := longPos to FContentLength - 1 do
if ContentData[ longIndex ] <> '"' then
strTemp := strTemp + ContentData[ longIndex ]
else break;
FFileName := strTemp;
delete( ContentData, 1, longIndex );
strTemp := #13#10#13#10;
FFileDataStart := longIndex + pos(strTemp, ContentData) + length(strTemp) - 1;
FFileDataEnd := FFileDataStart;
intDelimterLength := length( FDelimeter );
FindEndOfFileData := false;
while FFileDataEnd <= FContentLength - intDelimterLength do
begin
FindEndOfFileData := true;
for ALongInt := 0 to intDelimterLength - 1 do
if Byte( FDelimeter[ ALongInt + 1 ] ) <>
FContentData[ FFileDataEnd + ALongInt ] then
begin
FindEndOfFileData := false;
break;
end;
if FindEndOfFileData then break;
FFileDataEnd := FFileDataEnd + 1;
end;
if not FindEndOfFileData then FFileDataEnd := FFileDataStart - 1
else FFileDataEnd := FFileDataEnd - 3;
end;
Function TUploadFile.GetFileName: OleVariant;
begin
result := FFileName;)
end;
function TUploadFile.GetFileSize: OleVariant;
begin
result := FFileDataEnd - FFileDataStart + 1;
end;
function TUploadFile.SaveFileAs(FileName: OleVariant): OleVariant;
var
longIndex : LongInt;
AFile : file of byte;
byteData : Byte;
begin
result := true;
try
assign( AFile, FileName );
rewrite( AFile );
for longIndex := FFileDataStart to FFileDataEnd do
begin
byteData := Byte( FContentData[ longIndex ] );
Write( AFile, byteData );
end;
CloseFile( AFile );
except
result := false;
end;
end;
function TUploadFile.SaveFile: OleVariant;
var
CurrentFilePath : string;
begin
CurrentFilePath := FScriptingContext.Request.ServerVariables['PATH_TRANSLATED'];
CurrentFilePath := ExtractFilePath( CurrentFilePath );
Result := SaveFileAs( CurrentFilePath + ExtractFileName( FFileName ));
end;
파일얼리기
<% dim Upload, FileName
set Upload = Server.CreateObject("MyUpload.UploadFile")
FileName = Upload.GetFileName
Response.Write "
파일저장《"&FileName&"》......"
if Upload.SaveFile then
Response.Write "
파일《"&FileName&"》업로드성공。"
Response.Write "
파일크기"&Upload.GetFileSize&"바이트。"
else
Response.Write "
파일《"&FileName&"》업로드실패。"
end if
set Upload=nothing %>
四、几点说明
1、DLL크기215K,
DLL크기61K。
PWIN98+Delphi3.0+PWS4.0통과