attachment-server/incl_attachment_dl.php

68 lines
1.5 KiB
PHP

<?php
if(count($action)<2) {
gen_error_400("missing argument action[1]");
exit;
}
//change $action[1](cid) based on $alias2cid_l
if(count($action)>1&&strlen($action[1])>0) {
require(__DIR__."/phplib/libvar_alias2cid.php");
$alias2cid=[];
if(array_key_exists($game, $alias2cid_l)) {
$alias2cid=$alias2cid_l[$game];
}
unset($alias2cid_l);
if(array_key_exists($action[1], $alias2cid)) {
$action[1]=$alias2cid[$action[1]];
}
unset($alias2cid);
}
$cid=$action[1];
require(__DIR__."/phplib/libvar_cid2tid.php");
if(!array_key_exists($game, $cid2tid_l)) {
gen_error_404("the game ".$game." does not exist");
exit;
}
$gtid_l=$cid2tid_l[$game];
unset($cid2tid_l);
if(!array_key_exists($cid, $gtid_l)) {
gen_error_404("the cid ".$cid." in game ".$game." does not exist");
exit;
}
$tid=$gtid_l[$cid];
require(__DIR__."/phplib/libvar_tid2proj.php");
if(!array_key_exists($tid, $tid2proj_l)) {
gen_error_500("the tid ".$tid." does not exist");
exit;
}
$proj=$tid2proj_l[$tid];
$thash=gen_team_hash($ginfo["gsalt"], substr($cid, strlen("cid_")), $team_token);
$GLOBALS["game"]=$game;
$GLOBALS["team_id"]=$team_id;
$GLOBALS["team_token"]=$team_token;
$GLOBALS["action"]=$action;
$GLOBALS["cid"]=$cid;
$GLOBALS["tid"]=$tid;
$GLOBALS["proj"]=$proj;
$fn=make_attachment($thash);
header("Cache-Control: public, max-age=600");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$fn[0]."\"");
header("Content-Length: ".strlen($fn[1]));
echo $fn[1];