uses fphttpclient;
function UploadFile(const AURL, AFieldName, AFileName: String; out AError: String): Boolean;
var
SS: TStringStream;
HTTPClient: TFPHTTPClient;
begin
Result := False;
SS := TStringStream.Create('');
try
HTTPClient := TFPHTTPClient.Create(nil);
try
try
HttpClient.FileFormPost(AURL, AFieldName, AFileName, SS);
except
on E: Exception do
AError := E.Message;
end;
Result := SS.DataString = 'zipok';
finally
HTTPClient.Free;
HTTPClient := nil;
end;
finally
SS.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ErrMsg: String;
begin
if UploadFile('http://localhost/upload.php', 'zip', 'd:\test.zip', ErrMsg) then
ShowMessage('Successfully uploaded')
else
ShowMessage('Cannot upload file: ' + sLineBreak + ErrMsg);
end;