Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit/AppGameKit Studio Showcase / HTTP Multi-File Upload

Author
Message
Janku Ayanami
8
Years of Service
User Offline
Joined: 31st Aug 2015
Location: Namibia
Posted: 7th Sep 2015 11:43
<Background> Don't read this if you are just interested in the code
I was a little interested in syncing some data from my PC and android phone to the same site with ease. I realized in APK2 that in Tier1 you cannot write to the external storage (I could be wrong but I found no code as of yet, would be nice to do so thought). So I thought about writing a web service, I found some code and modified it to suit my needs.

So what the code does is to check the media directory for text files (txt) and upload all of them to a web script. If the file has been uploaded it is deleted in the local directory. If the file fails it is left for a next upload session.

Both the application and the web script keeps a log (the application log tends to get big due to the way it is written, you'll see he he)

<Code> Here is the business part
I only wrote one file for this because I wanted to keep it as simple as possible. First is the application code and then the web script.

Application code (main.agc)


Web Script (upload.php)
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 7th Sep 2015 11:56
Very useful, thanks for sharing. Naphier posted something similar, but it is always good to have several examples and methods.

You should probably add some security to the upload, otherwise anybody could use your PHP script to upload malicious files. Use the parameters in SendHTTPfile() to add a hash key which is checked in the PHP code.

I was about to research how to add subfolders in PHP, you have just solved that challenge for me

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 7th Sep 2015 18:39
Quote: "I was about to research how to add subfolders in PHP, you have just solved that challenge for me "

I need to do some more exploring into PHP also.

Quote: "Don't read this if you are just interested in the code"

lol
Yeah, right.

This is very nice, thank you for sharing.
Welcome to the forums! (in case i forgot to tell you that in the other thread)


Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
Janku Ayanami
8
Years of Service
User Offline
Joined: 31st Aug 2015
Location: Namibia
Posted: 8th Sep 2015 09:18
Thanks guys, I thought I'd share some of my projects. I am learning as I go along so I have a lot of projects that only tests and verifies one function.

Quote: "You should probably add some security to the upload, otherwise anybody could use your PHP script to upload malicious files. Use the parameters in SendHTTPfile() to add a hash key which is checked in the PHP code."

Noted, my website was compromised at one stage because I forgot to secure file uploads. I was busy testing scripts and I forgot to remove them lol.

Quote: "I was about to research how to add subfolders in PHP, you have just solved that challenge for me"

I needed to make sure on that because I wanted to build the main application for multiple users so I used the post vars to send a username or something similar.

In essence, the code I posted is not 100 % completed because I left out some things that might have missed my intention, which is to upload multiple files.

But thanks again for the feedback, anything always helps, even when its negative.

Login to post a reply

Server time is: 2024-03-29 15:54:47
Your offset time is: 2024-03-29 15:54:47