How to convert the parameters of an HTML webform to use with TIdHTTP in Delphi?
I have a web server, with PHP, and a function to upload files. Via a web browser, I can send files without problems, but when I use TIdHTTP, it presents an error.
This is the HTML for the file upload page:
<html>
<head>
<title>Upload de Arquivos com PHP</title>
</head>
<body>
<form method="post" action="recebe_upload.php" enctype="multipart/form-data">
<label>Arquivo:</label>
<input type="file" name="arquivo" />
<input type="submit" value="Enviar" />
</form>
</body>
</html>
This is the procedure I used to send the files:
procedure TForm1.Button1Click(Sender: TObject);
var
Response, URL : String;
LHTTPClient : TIdHTTP;
Lista : TIdMultiPartFormDataStream;
server, script, caminhoarq : string;
begin
URL := 'http://192.168.15.101/RECEBE_UPLOAD.php\';
Lista := TIdMultiPartFormDataStream.Create;
HTTPClient := TIdHTTP.Create;
HTTPClient.ProtocolVersion := pv1_1;
HTTPClient.Request.ContentType := 'utf-8';
HTTPClient.Request.UserAgent := 'Mozilla/3.0 (compatible;Indy Library)';
HTTPClient.HTTPOptions := [hoForceEncodeParams, hoKeepOrigProtocol];
Response := '';
try
try
Lista.AddFormField('Arquivo','C:\Client\teste.txt');
Response := UTF8Decode(Trim(HTTPClient.Post(URL, Lista)));
memo1.Lines.add(response);
except
on e : exception do
ShowMessage('Erro ao enviar arquivo ao servidor! Detalhes: '+e.Message);
end;
finally
Lista.Free;
HTTPClient.free;
end;
end;
This is the error message I get:
<br />
<b>Notice</b>: Undefined index: arquivo in <b>C:\xampp\htdocs\RECEBE_UPLOAD.php</b> on line <b>22</b><br />
<br />
<b>Notice</b>: Undefined index: arquivo in <b>C:\xampp\htdocs\RECEBE_UPLOAD.php</b> on line <b>30</b><br />
<br />
<b>Strict Standards</b>: Only variables should be passed by reference in <b>C:\xampp\htdocs\RECEBE_UPLOAD.php</b> on line <b>30</b><br />