Luciano Veneziano 1 Posted March 15, 2022 Hi everyone I have a PHP file that uploads images to me. I should send with HTTPS and post the parameters from Delphi like this. <form action = "UPLOAD.PHP" enctype = "multipart / form-data"> <input type = "file" name = "upfile" required /> <input type = "submit" value = "Upload" /> </form> Unfortunately I'm not very good, I was able to make calls in https and post, but I could not set up idHTTP correctly Has anyone already encountered this problem? Thanks to all. Share this post Link to post
Remy Lebeau 1394 Posted March 15, 2022 (edited) 4 hours ago, Luciano Veneziano said: I was able to make calls in https and post, but I could not set up idHTTP correctly It should look like this: uses ..., IdMultipartFormDataStream; var PostData: TIdMultipartFormDataStream; begin PostData := TIdMultipartFormDataStream.Create; try PostData.AddFile('upfile', 'C:\path\filename'); IdHTTP.Post('https://server/UPLOAD.PHP', PostData); finally PostData.Free; end; end; Edited March 15, 2022 by Remy Lebeau Share this post Link to post
Luciano Veneziano 1 Posted March 15, 2022 (edited) Funziona perfettamente: function httpsUpload(URL : string; fname : String ) : String; var LRequest: THTTPClient; LFormData: TMultipartFormData; LResponse: TStringStream; begin LRequest := THTTPClient.Create; LFormData := TMultipartFormData.Create(); LResponse := TStringStream.Create; try LFormData.AddField('json', '{"id":1,"user":"Luciano"}'); //optional LFormData.AddFile('file', fname); LRequest.Post(URL, LFormData, LResponse); Result := LResponse.DataString; finally LFormData.Free; LResponse.Free; LRequest.Free; end; end; phpfile <?php include_once("local/setup.php"); $where = $_FILES["file"]["name"]; if(move_uploaded_file($_FILES["file"]["tmp_name"], $where)) { echo "OK\r\n"; } else { echo "ERR\r\n"; } print_r($_FILES); ?> Edited March 15, 2022 by Luciano Veneziano 1 Share this post Link to post