user1709803
user1709803

Reputation:

How to create a .txt file on a server using Android?

I have been given a task using an Android application whereby the user is presented with a "Contact Us" form on the device's screen and once they fill their name, subject and question, the program should create a file on my server in a particular folder and call the file something like enquiry(date)(time) for uniqueness. I had a delve around and found some code that creates a file in /data/data/your_project_package_structure/files/samplefile.txt (link to post: How to create a file in Android?

So I was thinking: do I either use this code to create the file locally and then move the file to my server using something like file.Rename or do I create a custom solution (which I have no idea how to achieve)?

I would appreciate if anybody out there is capable of giving me some advice on this one and I hope other people find this helpful too.

Code samples will be mostly welcome

Upvotes: 0

Views: 285

Answers (1)

Stefan de Bruijn
Stefan de Bruijn

Reputation: 6319

You can go 2 ways with this (probably more actually...)

I'll assume your server runs on PHP. Other server languages will not really change the options, just the execution.

  1. You can create your file locally (seems you already figured out how to do that) and just upload that file to your server. You can google around for uploading to $_FILES which basically is a simple stream of bytes. The server will just have to save the file somewhere.

  2. Leave this work up to your server instead. Just send the info over in a post or get request, fetch the data with $_GET or $_POST and create a file & save on server. This would probably be my personal choice, since you'll want to get any work a server can do, out of the hands of your much more limited mobile, saving resources such as data and battery usage.

Upvotes: 1

Related Questions