C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[14102] 파일올리기인데 delphi소스에요 참고하시고 답변 좀 꼭!! ^^
김영환 [semon] 1652 읽음    2002-01-02 18:08
안녕하세요  여러분  제가요즘 빌더의 asp프로그래밍때매 뱅뱅돌고 있습니다.
하도 급해서 dephi소스까지 찾아서 참고하는데  문재가 안 풀리네요

여러분 도움 좀 부탁드립니다.
제가 
Request->get_TotalBytes(&FContentLength);
AoleVariant=Variant(FContentLength);
Request_>BinaryRead(AoleVariant,contentdata);
Request->BinaryRead(contentData)해서 보니contentdata에 값이 들어온 것은 분명합니다.
Contentdata에들어 있는 마이너리형의 값을 String이나 AnsiString값으로 가져오지를 못하고 있습니다.
그리고  String=contentdata..operator AnsiString()를 썼을 경우 jpg같은 택스트형이아닌 문서는
읽어드리지를 못하네여
Reponse->Write(Varint(String)하면 파일부분이 안보이구요
Reponse->BinaryWrite(Varint(String)해서 보면 깨진글입니다.

답답한 마음에 이렇게 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통과

+ -

관련 글 리스트
14102 파일올리기인데 delphi소스에요 참고하시고 답변 좀 꼭!! ^^ 김영환 1652 2002/01/02
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.