Android Question HttpUtils2 file upload issues

Florin

Member
Licensed User
Longtime User
Hi,
For some time now I try to find a way to upload a file to a server, works great with HTML, never with B4A. Please help.
Find below the codes for html, php and b4a, which I have simplified to maximum in order to get some positive results ...


HTML:

<!DOCTYPE html>
<html>
<body>
<form action="upload2.php" method="post" enctype="multipart/form-data">
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>


PHP: upload2.php

<?php
$target_dir = "kp/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
?>



B4A:
SubButPostFile_Click
job2.Initialize("Job2",Me)
job2.PostFile("http://www.xxxxxxx.yy/upload2.php", File.DirRootExternal, "p.jpg")
EndSub
 

walterf25

Expert
Licensed User
Longtime User
Hi,
For some time now I try to find a way to upload a file to a server, works great with HTML, never with B4A. Please help.
Find below the codes for html, php and b4a, which I have simplified to maximum in order to get some positive results ...


HTML:

<!DOCTYPE html>
<html>
<body>
<form action="upload2.php" method="post" enctype="multipart/form-data">
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>


PHP: upload2.php

<?php
$target_dir = "kp/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
?>



B4A:
SubButPostFile_Click
job2.Initialize("Job2",Me)
job2.PostFile("http://www.xxxxxxx.yy/upload2.php", File.DirRootExternal, "p.jpg")
EndSub
What is the issue exactly, do you get any errors? posting the errors may help others help you figuring out the issue?

It is also helpful to use the
B4X:
when posting code, it makes it easier to read.

Cheers,
Walter
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
See my signature for a example on how to use file upload to php with a multipartpost
 
Upvote 0
Top