Created
June 17, 2021 02:38
-
-
Save atsu666/28e85f02af94ec194c6930fc589538aa to your computer and use it in GitHub Desktop.
php/ACMS/POST/Download.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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