file.magicExt
単なるテキストファイル (utf-8) のファイルがあります。例:
hello
私は持っていますindex.php
:
<?php
echo '<a href="file.magicExt">file</a>';
私が望むのは、ユーザーが「ファイル」リンクをクリックしたときに「開く」ダイアログを表示することです。
代わりに、ブラウザ (Firefox、Chrome) にファイルの内容が表示されます。
私はそのようなものでそれをやり遂げましたfile.php
:
<?php
// We'll be outputting a .magicExt
header('Content-Type: application/magicExt');
// It will be called downloaded.magicExt
header('Content-Disposition: attachment; filename="downloaded.magicExt"');
// The .magicExt source is in original.magicExt
readfile('original.magicExt');
PHP header() 関数に基づく
そしてそれindex.php
:
echo '<a href="file.php">file</a>';