Skip to content

Instantly share code, notes, and snippets.

@atsu666
Created June 17, 2021 02:38
Show Gist options
  • Select an option

  • Save atsu666/28e85f02af94ec194c6930fc589538aa to your computer and use it in GitHub Desktop.

Select an option

Save atsu666/28e85f02af94ec194c6930fc589538aa to your computer and use it in GitHub Desktop.
php/ACMS/POST/Download.php
<?php
class ACMS_POST_Download extends ACMS_POST
{
var $isCacheDelete = false;
protected $isCSRF = false;
function post()
{
$Q = \Common::getUriObject($this->Post);
$headerAry = array(
'User-Agent: acms',
'Accept-Language: ' . HTTP_ACCEPT_LANGUAGE,
);
if ( SESSION_USE_COOKIE ) {
$Q->delete('sid');
$headerAry[] = 'Cookie: ' . SESSION_NAME . '=' . ACMS_SID;
}
$url = acmsLink($Q, true, true);
try {
$contents = '';
$req = \Http::init($url, 'GET');
$req->setRequestHeaders($headerAry);
$response = $req->send();
$responseHeaders = $response->getResponseHeader();
$body = $response->getResponseBody();
if ( 1
and isset($responseHeaders['Content-Type'])
and preg_match('@^text/[^;]+; charset=(.*)$@', $responseHeaders['Content-Type'], $match)
) {
$contents = mb_convert_encoding($body, 'UTF-8', $match[1]);
}
if ($toCharset = $this->Post->get('charset')) {
$contents = mb_convert_encoding($contents, $toCharset, 'UTF-8');
}
header('Content-Length: '.strlen($contents));
if (strpos(UA, 'MSIE')) {
header('Content-Type: text/download');
} else {
header('Content-Disposition: attachment');
header('Content-Type: application/octet-stream');
}
die($contents);
} catch (\Exception $e) {
echo $e->getMessage();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment