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 Classic Chat / AGK/PHP http question

Author
Message
easter bunny
11
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 2nd Aug 2013 06:37 Edited at: 2nd Aug 2013 06:48
I'm not that great at PHP and I need to upload a file from an AppGameKit app to a server, but I can't figure out how to receive the file

AGK code:


My non-working PHP code:


getting the names parameter works fine, the file code was copied off a tutorial website, the problem is that all the docs I could find online were about receiving a file from a form, not an app.

Auger
12
Years of Service
User Offline
Joined: 21st Aug 2011
Location: Out There
Posted: 2nd Aug 2013 08:29
I'm a php newbie, but this might work

xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 2nd Aug 2013 08:30 Edited at: 2nd Aug 2013 08:34
The $_FILES superglobal in PHP is an associative array containing details about the uploaded content. AppGameKit uses the key "myfile" to store information about the upload. So, you can retrieve the filename and the PHP temporary filename in PHP using:



(If you are moving the uploaded file to another folder on the server, you can prepend it as needed to the $upload_file variable as long as the indicated directory already exists on the server).

You can then pass the temporary and final file data to the move_uploaded_file function to complete the transfer.



For simplicity I echo '1' if successful, '0' if not. This way in AppGameKit you can read the HTTP response and take whatever action depending on if it was successful or not.

A simple working PHP script may look like:



P.S., You can retrieve and store PHP's temporary upload directory if needed for any reason by using something like:

easter bunny
11
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 2nd Aug 2013 09:10
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 2nd Aug 2013 18:40
Also, there is no need to put the HTML stuff in your php file. It just adds output that you don't need at all.

Simply do the echo call for anything that you want to be seen by the AppGameKit app. Otherwise, you will get all the HTML text in the response from the site.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master

Login to post a reply

Server time is: 2024-04-27 11:47:21
Your offset time is: 2024-04-27 11:47:21