[PHP] 纯文本查看 复制代码 $filename = arg('filename', 'app.exe');
$template = arg('biaoshi', '[MC]xxxxxxxxxxx');
$code = arg('huan');
if (!$code) exit('请指定邀请码!');
if (11 != strlen($code)) exit('邀请码不正确!');
$filePath = "./$filename";
if (!file_exists($filePath)) {
header('HTTP/1.1 404 NOT FOUND');
} else {
$temp_file = "./temp-$code.exe";
if (!file_exists($temp_file)) {
$search = pack("A*", $template);
$replace = pack("A*", "[MC]$code");
$content = file_get_contents($filePath);
$replacedContent = str_replace($search, $replace, $content);
file_put_contents($temp_file, $replacedContent);
}
$file = fopen($temp_file, "rb");
header("Content-type: application/octet-stream");
header("Accept-Ranges: bytes");
header("Accept-Length: ".filesize($temp_file));
header("Content-Disposition: attachment; filename=".pathinfo($filePath, PATHINFO_BASENAME));
echo fread($file, filesize($temp_file));
fclose($file);
unlink($temp_file);
exit;
}
function arg($name = null, $default = null, $trim = true) {
if ($name) {
if (!isset($_REQUEST[$name])) return $default;
$arg = $_REQUEST[$name];
if ($trim) $arg = trim($arg);
} else {
$arg = $_REQUEST;
}
return $arg;
}
|