本文整理自网络,侵删。
unit Unit1;
interface
usesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,IdHTTP, StdCtrls,IdMultiPartFormData;
typeTForm1 = class(TForm)Button1: TButton;IdHTTP1: TIdHTTP;OpenDialog1: TOpenDialog;procedure Button1Click(Sender: TObject);
private{ Private declarations }public{ Public declarations }end;
varForm1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);varres : String;ms : TIdMultiPartFormDataStream;h: TIdhttp;f:string;beginif Opendialog1.Execute thenf:=Opendialog1.FileName;if f='' then exit;tryms := TIdMultiPartFormDataStream.Create;h := Tidhttp.Create(nil);ms.AddFile('file1',f,'');idhttp1.Request.ContentType := 'multipart/form-data' ;res:=h.Post('http://www.oro.com/Admin/u.asp?menu=up',ms);if res='上传成功' thenApplication.MessageBox('图片上传成功!','提示',MB_OK+MB_ICONASTERISK)elseApplication.MessageBox('图片上传失败!','ERROR',MB_OK+MB_ICONSTOP);finallyms.Free;end;end;
end.
相关阅读 >>
Delphi enumwindows 获取窗体句柄 进程id 窗体信息
Delphi showmainform := false 失效的解决办法
Delphi android 安卓系统 关闭打开(显示隐藏)输入法
更多相关阅读请进入《Delphi》频道 >>