*
token : string, put token returned by appropriate
* XMLRPC call
*
*
* On success, returns HTTP return code 200.
*
* On errors, returns HTTP return code >200
* The possible error codes are:
*
* - 400 - Incorrect parameters passed to method
* - 403 - Access denied
* - 500 - Application error
*
*
* @see XR_LocStor
*/
require_once '../conf.php';
require_once 'DB.php';
require_once '../Archive.php';
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
$dbc = DB::connect($config['dsn'], TRUE);
$dbc->setFetchMode(DB_FETCHMODE_ASSOC);
$gb = &new Archive($dbc, $config);
function http_error($code, $err){
header("HTTP/1.1 $code");
header("Content-type: text/plain; charset=UTF-8");
echo "$err\r\n";
exit;
}
if(preg_match("|^[0-9a-fA-F]{16}$|", $_REQUEST['token'])){
$token = $_REQUEST['token'];
}else{
http_error(400, "Error on token parameter. ({$_REQUEST['token']})");
}
$tc = $gb->bsCheckToken($token, 'put');
if(PEAR::isError($tc)){ http_error(500, $ex->getMessage()); }
if(!$tc){ http_error(403, "Token not valid."); }
#var_dump($tc); exit;
header("Content-type: text/plain");
#var_dump($_SERVER); var_dump($_REQUEST); exit;
#$destfile = $_SERVER['PATH_TRANSLATED'];
$destfile = "{$config['accessDir']}/{$token}";
/* PUT data comes in on the input stream */
$putdata = @fopen("php://input", "r") or
http_error(500, "put.php: Can't read input");
/* Open a file for writing */
$fp = @fopen($destfile, "ab") or
http_error(500, "put.php: Can't write to destination file (token=$token)");
/* Read the data 1 KB at a time and write to the file */
while ($data = fread($putdata, 1024)){
fwrite($fp, $data);
}
/* Close the streams */
fclose($fp);
fclose($putdata);
header("HTTP/1.1 200");
?>