diff options
author | michael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2012-07-04 12:45:46 +0000 |
---|---|---|
committer | michael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2012-07-04 12:45:46 +0000 |
commit | edc9d67fe8d22c05e01df13f45eb33289f8ef3b7 (patch) | |
tree | a46bcee2f88b27d2ce8b5707865db198276b97c1 /packages/fcl-web/src/base/httpdefs.pp | |
parent | 5b29a0867b6bda9907587ad5f44774666cacf6f6 (diff) | |
download | fpc-edc9d67fe8d22c05e01df13f45eb33289f8ef3b7.tar.gz |
* Customization of upload dir
git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@21769 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/fcl-web/src/base/httpdefs.pp')
-rw-r--r-- | packages/fcl-web/src/base/httpdefs.pp | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/packages/fcl-web/src/base/httpdefs.pp b/packages/fcl-web/src/base/httpdefs.pp index 504008a761..dba2c8bbe4 100644 --- a/packages/fcl-web/src/base/httpdefs.pp +++ b/packages/fcl-web/src/base/httpdefs.pp @@ -293,7 +293,9 @@ type Procedure ProcessMultiPart(Stream : TStream; Const Boundary : String;SL:TStrings); virtual; Procedure ProcessQueryString(Const FQueryString : String; SL:TStrings); virtual; procedure ProcessURLEncoded(Stream : TStream;SL:TStrings); virtual; - Function GetTempUploadFileName : String; virtual; + Function RequestUploadDir : String; virtual; + Function GetTempUploadFileName(Const AName, AFileName : String; ASize : Int64) : String; virtual; + Procedure DeleteTempUploadedFiles; virtual; Procedure InitRequestVars; virtual; Procedure InitPostVars; virtual; Procedure InitGetVars; virtual; @@ -954,18 +956,8 @@ begin end; destructor TRequest.destroy; -var - i: Integer; - s: String; begin - //delete all temporary uploaded files created for this request if there is any - i := FFiles.Count; - if i > 0 then for i := i - 1 downto 0 do - begin - s := FFiles[i].LocalFileName; - if FileExists(s) then DeleteFile(s); - end; - // + DeleteTempUploadedFiles; FreeAndNil(FFiles); inherited destroy; end; @@ -1194,18 +1186,36 @@ begin {$ifdef CGIDEBUG}SendMethodExit('ProcessQueryString');{$endif CGIDEBUG} end; -function TRequest.GetTempUploadFileName: String; +Function TRequest.RequestUploadDir : String; begin -//Result:=GetTempFileName('/tmp/','CGI') {Hard coded path no good for all OS-es} -{ -GetTempDir returns the OS temporary directory if possible, or from the -environment variable TEMP . For CGI programs you need to pass global environment - variables, it is not automatic. For example in the Apache httpd.conf with a -"PassEnv TEMP" or "SetEnv TEMP /pathtotmpdir" line so the web server passes this - global environment variable to the CGI programs' local environment variables. -} - Result := GetTempFileName(GetTempDir, 'CGI'); + Result:=''; +end; + +Function TRequest.GetTempUploadFileName(Const AName, AFileName : String; ASize : Int64): String; + +Var + D : String; + +begin + D:=RequestUploadDir; + if (D='') then + D:=GetTempDir; // Note that this may require a TEMP environment variable to be set by the webserver. + Result:=GetTempFileName(D, 'CGI'); +end; + +Procedure TRequest.DeleteTempUploadedFiles; +var + i: Integer; + s: String; +begin + //delete all temporary uploaded files created for this request if there is any + i := FFiles.Count; + if i > 0 then for i := i - 1 downto 0 do + begin + s := FFiles[i].LocalFileName; + if FileExists(s) then DeleteFile(s); + end; end; procedure TRequest.InitRequestVars; @@ -1359,10 +1369,10 @@ begin else begin FI.DLen:=J; - FF:=GetTempUploadFileName; + FF:=GetTempUploadFileName(FI.name,FI.FileName,J); F:=TFileStream.Create(FF,fmCreate); Try - F.Write(FI.Data[1],Length(FI.Data)); + F.Write(FI.Data[1],J); finally F.Free; end; |