require_once('../prepare.php');
function charge($p)
{
// ファイルのダウンロードを行う
if( $p['offset'] >= 0 && $p['count'] > 0 )
{
ini_set('default_charset', '');
mb_http_output('pass');
header('Content-Type: application/x-up-download');
$fp = fopen($p['name'], "rb");
fseek($fp, $p['offset'], 0);
print fread($fp, $p['count']);
fclose($fp);
// ファイルが存在しない場合
}
else if($p['offset'] == 0 && $p['count'] == 0)
{
header('Content-Type: application/x-up-download');
header('Content-Length: 0');
header('\n');
// ダウンロードに成功した場合
}
else if($p['offset'] == -1 && $p['count'] == -1)
{
$result = "success";
switch($_COOKIE['type'])
{
case 300:
$sc = EZ_SC300;
$pc = EZ_PC300;
break;
case 500:
$sc = EZ_SC500;
$pc = EZ_PC500;
break;
}
$uid = $_COOKIE['uid'];
$isp = $_COOKIE['isp'];
// 残りポイントが30以上ならば購入不可
$member = get_member_info($uid);
$cur_point = $member["cur_point"];
if($cur_point >= 30)
{
$result = "point over";
}
else
{
// 課金処理
$st = date("YmdHis");
$et = $st;
$exec = "./charge isp={$isp} cp=" . EZ_CP . " sc={$sc} pc={$pc} st={$st} et={$et} res=N";
chdir(dirname(__FILE__) . "/bin");
putenv("REQUEST_METHOD=GET");
putenv("QUERY_STRING=ac=" . $_COOKIE['ac']);
system($exec, $ret);
if($ret == 0)
{
// DBに個別課金情報を登録する
$ret = charge_exec($uid, 'e');
if($ret != 0)
{
$result = "point error";
}
}
else
{
$result = "charge error";
}
}
// log書込
chdir(dirname(__FILE__));
$script = basename($_SERVER['SCRIPT_NAME']);
$log = sprintf("%s : uid=%s, result=%s, exec=%s", $script, $uid, $result, $exec);
member_trace(REGBUYST_REGIST, $log);
setcookie("type", "", time() - 3600);
setcookie("ac", "", time() - 3600);
setcookie("uid", "", time() - 3600);
setcookie("isp", "", time() - 3600);
header('Content-Type: text/x-hdml;charset=Shift_JIS');
print "\n";
print "\n";
print "\n";
print "ダウンロードに成功しました。\n";
print "\n";
print "\n";
// ダウンロードに失敗した場合
}
else if($p['offset'] == -1 && $p['count'] == -2)
{
header('Content-Type: text/x-hdml;charset=Shift_JIS');
print "\n";
print "\n";
print "\n";
print "ダウンロード失敗しました。\n";
print "\n";
print "\n";
}
else
{
header('Content-Type: text/x-hdml;charset=Shift_JIS');
print "\n";
print "\n";
print "\n";
print "ダウンロード失敗しました。\n";
print "\n";
print "\n";
}
}
charge($p);
?>