-
-
Save sunghwan2789/2d5f94f3ddf46018d7dca482c3f6a905 to your computer and use it in GitHub Desktop.
Content-Disposition: attachment で日本語ファイル名をダウンロードさせるテスト
This file contains 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 | |
$t = isset($_GET['t']) ? $_GET['t'] : null; | |
$org = '此のファイル test.php'; | |
$fn = array( | |
'A: UTF-8 Raw' => 'Content-Disposition: attachment; filename="' . $org . '"', | |
'B: UTF-8 URL Encoded' => 'Content-Disposition: attachment; filename="' . rawurlencode($org) . '"', | |
'C: RFC 2231' => 'Content-Disposition: attachment; filename*=UTF-8\'\'' . rawurlencode($org), | |
'D: UTF-8 Raw + RFC 2231' => 'Content-Disposition: attachment; filename="' . $org . '"; filename*=UTF-8\'\'' . rawurlencode($org), | |
'E: UTF-8 URL Encoded + RFC 2231' => 'Content-Disposition: attachment; filename="' . rawurlencode($org) . '"; filename*=UTF-8\'\'' . rawurlencode($org), | |
); | |
if (isset($fn[$t])) { | |
header('Content-Type: application/octet-stream'); | |
header($fn[$t]); | |
header('Content-Length: ' . filesize(__FILE__)); | |
readfile(__FILE__); | |
exit; | |
} | |
header('Content-Type: text/html; charset=UTF-8'); | |
?> | |
<ul> | |
<?php foreach ($fn as $i => $n): ?> | |
<li><a href="?t=<?php echo rawurlencode($i); ?>">Download <?php echo htmlspecialchars($i); ?></a></li> | |
<?php endforeach; ?> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment