0

我有一个文件file.magicExt,它只是一个文本文件(utf-8),例如:

hello

我有一个index.php

<?php

echo '<a href="file.magicExt">file</a>';

我想要的是当用户单击“文件”链接时显示“打开方式”对话框。

相反,浏览器(Firefox、Chrome)显示文件内容。

4

1 回答 1

0

我用这样的方式完成了它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>';
于 2015-03-07T01:57:25.477 回答