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
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