Be sure to have a folder called uploads in your root folder of your web server. In Tier 1 file.txt should be in your media folder. In Tier 2 your file.txt should be in your Final folder (or where your .exe is generated to)
file_upload.php
<?PHP
// If there is an error, Send Error Response //
if ($_FILES["myfile"]["error"] > 0){
echo "Error: " . $_FILES["myfile"]["error"] . "\n";
}
// Else Send File Upload Response //
else {
echo "Upload: " . $_FILES["myfile"]["name"] . "\n";
echo "Type: " . $_FILES["myfile"]["type"] . "\n";
echo "Size: " . ($_FILES["myfile"]["size"] / 1024) . " Kb\n";
echo "Temp. File Stored in: " . $_FILES["myfile"]["tmp_name"] . " \n";
// If the file allready exists, do not copy over it. //
if (file_exists("upload/" . $_FILES["myfile"]["name"]))
{
echo $_FILES["myfile"]["name"] . " already exists. \n\n";
}
// Else move to uploads folder //
else
{
move_uploaded_file($_FILES["myfile"]["tmp_name"], "upload/" . $_FILES["myfile"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["myfile"]["name"] . " \n\n";
}
}
?>
Tier 1: HTTP Send File
HTTP = 0 // The HTTP Connection
sending = 0 // Flag if file is sending, returned from SendHTTPFile()
// Setup Display //
SetVirtualResolution(640, 480)
// Info Text //
CreateText(1, "Press 'Left' Key to send file.")
SetTextSize(1, 12)
// Server Response Text //
CreateText(2, "")
SetTextSize(2, 12)
SetTextPosition(2, 0, 20)
// Create the HTTP Connection //
HTTP = CreateHTTPConnection() // Create the HTTP Connection
SetHTTPHost(HTTP, "www.YourServer.com", 0) // Set the HTTP Host
DO
// If Left key pressed, Send file. //
IF GetRawKeyPressed(37) = 1
SetTextString(1, "Sending 'File.txt'")
sending = SendHTTPFile(HTTP, "file_upload.php", "", "file.txt")
ENDIF
// Display Progress //
IF GetHTTPFileComplete(HTTP) = 0 AND sending = 1
SetTextString(1, Str( GetHTTPFileProgress(HTTP) ) )
ELSEIF GetHTTPFileComplete(HTTP) = 1 AND sending = 1
SetTextString(1, "Complete! -Click Anywhere to End-" )
ENDIF
// Check if there is a Response from the Server.
// If so, Set Text 2 to display it
IF GetHTTPResponseReady(HTTP) = 1
SetTextString(2, GetHTTPResponse(HTTP))
ENDIF
// If Pointer Pressed, End //
IF GetPointerPressed() = 1 THEN END
// Sync //
SYNC()
LOOP
Tier 2: HTTP Send File
// Includes, namespace and prototypes
#include "template.h"
using namespace AGK;
app App;
int HTTP = 0;
bool sending = 0;
// START //
void app::Begin( void )
{
// Setup Display //
agk::SetVirtualResolution(640, 480);
// Info Text //
agk::CreateText(1, "Press 'Left' Key to send file.");
agk::SetTextSize(1, 12);
// Server Response Text //
agk::CreateText(2, "");
agk::SetTextSize(2, 12);
agk::SetTextPosition(2, 0, 20);
// Create the HTTP Connection //
HTTP = agk::CreateHTTPConnection(); // Create the HTTP Connection
agk::SetHTTPHost(HTTP, "www.YourServer.com", 0); // Set the HTTP Host
}
// MAIN LOOP //
void app::Loop ( void )
{
// If left key pressed, send file //
if(agk::GetRawKeyPressed(37)){
agk::SetTextString(1, "Sending 'File.txt'");
sending = agk::SendHTTPFile(HTTP, "file_upload.php", "", "file.txt");
}
// Display File Progress //
if(agk::GetHTTPFileComplete(HTTP)==0 && sending == 1){
agk::SetTextString(1, agk::Str( agk::GetHTTPFileProgress(HTTP) ) );
}
else if(agk::GetHTTPFileComplete(HTTP)==1 && sending == 1){
agk::SetTextString(1, "Complete! -Click Anywhere to End-" );
}
// Check if there is a Response from the Server.
// If so, Set Text 2 to display it
if(agk::GetHTTPResponseReady(HTTP)){
agk::SetTextString(2, agk::GetHTTPResponseC(HTTP));
}
// If pointer pressed, End //
if(agk::GetPointerPressed() == 1){ App.End(); }
// Sync //
agk::Sync();
}
// END //
void app::End ( void )
{
// Cleanup Connection //
agk::CloseHTTPConnection(HTTP);
// exit //
exit(0);
}
Hope this helps everyone out, and I hope TGC updates the Documentation a little, be good to know that the Input Field name is myfile.