The third parameter (szPostData) is for passing information. It is done in the form of 'varname=varvalue'. If you have more than one variable, 'var1name=var1val&var2name=var2val'. This is discussed in the help page for SendHTTPFile.
The variable name may consist of a-z, numbers and underscore (to be safe) and must start with a letter or underscore.
The variable data may not contain spaces or characters other than a-z, 0-9, underscore (_), percent (%). Actually, it can include others, but it is safest to replace them with the appropriate escaping using the percent character and the hex representation of the ascii value. A space is represented by '%20' (percent,two,zero) without the quotes. A dash is '%2D', backslash is '%2F', etc. (find a good ASCII character set chart with the decimal and hex values).
On the server side, inside your post.php file, you will extract the values from $_REQUEST['varname'] (in this case, you do use the quotes). Something like this:
<?php
// get the value
$myvar = $_REQUEST['myvarname'];
// check for blank
if ($myvar == '')
{
// oops, error, do something (like return a zero as an error value)
echo '0';
exit;
}
// do whatever you need with the variables and the file
// more on this later in post
// send a return value to indicate good (or something else)
echo '1|all is good';
?>
I don't know if the AppGameKit stuff is using the standard file transfer protocols, but assuming it does, it will show up in the $_FILES array. This array requires a name for the index and the AppGameKit help doesn't specify what it is. Can someone at TGC please help with this information?
Assuming, just for the sake of creating an example, that the name to use is the same as set in the szLocalFile parameter.
Lets assume you make a call like this:
SendHTTPFile(iHTTP,"post.php","storefilein=somepublicdir",'post.txt')
This is what the PHP processing within your post.php might look like (a more complete example than the one above and should be functional, assuming the passed directory exists and is writable):
<?php
// get the location to store the file in
$mydir = $_REQUEST['storefilein'];
// check for blank
if ($mydir == '')
{
// oops, error, do something (like return a zero and error message)
echo '0|missing directory location';
exit;
}
// get the file information
// this is the name of the actual file that was passed up
$fileName = $_FILES['post.txt']['name'];
// this is the complete path to the uploaded file
$tempLoc = $_FILES['post.txt']['tmp_name'];
// make sure nothing is blank
if ($fileName == "")
{
// oops
echo '0|missing uploaded file name';
exit;
}
if ($tempLoc == "")
{
// oops
echo '0|missing uploaded location';
exit;
}
// check to see if the file actually uploaded
if (!is_uploaded_file($tempLoc))
{
// oops
echo '0|file did not upload properly';
exit;
}
// build the path to store it in
// (the $_SERVER array gives information about the server processing the file and
// 'DOCUMENT_ROOT' is the root directory for the domain)
$store_in = $_SERVER['DOCUMENT_ROOT'].'/'.$mydir.'/'.$fileName;
// attempt to copy to target location
$ok = move_uploaded_file($tempLoc,$store_in);
// check results
if ($ok)
{
// send a return value to indicate good (or something else)
echo '1|all is good';
} else {
// oops
echo '0|failed to copy file';
}
?>
Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master