Home » U++ Library support » U++ MT-multithreading and servers » [SOLVED] File upload example
[SOLVED] File upload example [message #52428] |
Mon, 23 September 2019 19:42 |
|
forlano
Messages: 1185 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
Hello,
I need to upload a file within my U++ app to a server, say folder "uploaded".
Is there a ready to use example/reference? I was not able to find it.
Thanks,
Luigi
[Updated on: Sun, 09 August 2020 00:03] by Moderator Report message to a moderator
|
|
|
|
|
|
Re: File upload example [message #52439 is a reply to message #52436] |
Sun, 29 September 2019 13:11 |
|
forlano
Messages: 1185 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
Thanks.
After many tests I was able to perform the wanted operation.
Here is the U++ method
void fileupload::Upload()
{
String url = "http://localhost/uploads/transfer.php";
HttpRequest r(url);
String fn = "C:/upp/out/MyApps/MSBT17.Gui/test.pdf";
String s = LoadFile(fn);
r.POST();
r.Part("file", s , "multipart/form-data", fn);
r.Execute();
}
and this is the PHP script connected with the previous code:
<?php
//transfer.php
$target = "./". basename( $_FILES["file"]["name"] ) ;
if(move_uploaded_file($_FILES["file"]["tmp_name"], $target)) echo "1";
else echo "0";
?>
Is there a way to get the echoed "1" or "0" with r.something()?
Edit: Yes, of course:
String a;
a = r.Execute();
a contains the server answer.
Luigi
[Updated on: Sun, 29 September 2019 16:47] Report message to a moderator
|
|
|
|
|
Goto Forum:
Current Time: Thu Apr 25 14:05:42 CEST 2024
Total time taken to generate the page: 0.02051 seconds
|