Android Question HTTP Job Does Not Complete

dannyjon

Member
Licensed User
Longtime User
I have a simple HTTP job to post a file to a PHP script, which, as far as I know IS working ok.

Dim aspjob As HttpJob
aspjob.Initialize("aspjob","me")
aspjob.PostFile("http://xyz.com/upload.php",File.DirRootExternal,"filename")

There are no errors but the app on Android asks if I want to Wait or Stop.

I have checked and rechecked and can not see where I have gone wrong?

Many thanks
 

DonManfred

Expert
Licensed User
Longtime User
How big is the File you want to post?
Have you tried it with a smaller File?

You can also have a look AT the examples in my signature. .. multipartpost. ..
 
Last edited:
Upvote 0

dannyjon

Member
Licensed User
Longtime User
Tks for your reply.
The file is 2kb and I have tried other files as well.
I have tried the multipartpost script but it often (not always) returns the boolean False, even though the file DOES upload, so regretfully this method could not be used.
 
Upvote 0

dannyjon

Member
Licensed User
Longtime User
B4A Returns "Invalid File" from the PHP Script.


Sub btnSendTestFilePHP_Click
Dim pfile As HttpJob
pfile.Initialize("pfile",Me)
pfile.PostFile("http://xxx.xxx.co.uk/file_upload_restrict_save_move.php",File.DirRootExternal,"camicon.jpg")
End Sub

When calling the above URL in the browser and choosing the jpg it works file...

Here is the PHP Script:

<?php
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);

if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts)) {
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
} else {
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("upload/" . $_FILES["file"]["name"])) {
echo $_FILES["file"]["name"] . " already exists. ";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
} else {
echo "Invalid file";
}
?>
 
Upvote 0
Top