Android Question Upload file to php

Devv

Active Member
Licensed User
Longtime User
i'm using httpUtils to post file to my php script:
PHP:
<?php
   $PostData = file_get_contents("php://input");
   $File = fopen("test.mp3","wb");
   fwrite($File, $PostData);
   fclose($File);
 
?>

and the b4a code

B4X:
uploader.PostFile(url & "/1.php",File.DirInternal,"test.mp3")

every thing is working fine but i cant find a way to upload the file with a specific file name
i don't always want the name to be "test.mp3" how can i control the name from b4a ?
 

DonManfred

Expert
Licensed User
Longtime User
could you tell me which one of your 3 example can let me specify the file name, and why is ok http better that httputlis ?
okhttp replaces the old httputils. You are forced to do the update if you want to run your apps on Android 6+

Use the okHTTP download (3rd) as b4a part.
Use the PHP download (2nd) to see the php part.
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
okhttp replaces the old httputils. You are forced to do the update if you want to run your apps on Android 6+

Use the okHTTP download (3rd) as b4a part.
Use the PHP download (2nd) to see the php part.

OK i'm seeing it right now, what is the point from uploading the file as parts ?
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
I dont understand the question!?

your method will upload the file part by part right ?
my question is why we should upload the file as parts why not send it as one part ?
my files are small (<1mb) why should we make it parts then send it to the PHP < won't this make the upload slower ?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
your method will upload the file part by part right ?
It will use the right way to send multiple files to a php script. It´s like sending a form with multiple data...

The point is that you need to use the correct way to "read" the file from the the given post vars (using the $_FILES array)
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
It will use the right way to send multiple files to a php script. It´s like sending a form with multiple data...

The point is that you need to use the correct way to "read" the file from the the given post vars (using the $_FILES array)
DonManfred thanks a lot for your help , the soulution i folowed was passing a variable to php using the link
ex: mysite.com/test.php?name=1.mp3


 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
the soulution i folowed was passing a variable to php using the link
ex: mysite.com/test.php?name=1.mp3
But with this you CAN NOT send any filedata to the server.

It will work if you use the multipartupload though.
And additional with the multipart you are not limited to the maximum length of an url.

So, please ignore my tips and code what you want to.
I´m out!
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User

Strange , the method i posted worked for me perfectly i was able to upload any type of file with as much parameters i want.

anyway thanks for your help
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Strange , the method i posted worked for me perfectly i was able to upload any type of file with as much parameters i want.
If you use get (anything after the ? in the url) then yes. this will work. As long as the maximum length a url is allowed to have.
So, giving just a few values like ints this will work. but try to give 5 texts with a length of 32kb together with the filepayload as get parameters. You will reach the limit of an url
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User


good to know, thanks for the info i found in the internet it is about "2,083 characters" which will be more than enough for me

anyways you seem to bee a pro with http protocol
i'm using https post with username and password as parameters is that secure ? can any hacker or the isp know/ see my use name and password ?
ex: mysite.com/test.php?name=1.mp3&usr=mruser&psw=mrpassword
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…