PHP在标题页面中打开一个现有的csv / text文件

我可以在页面的标题中打开现有的文本文件或csv文件吗? (即当我将下面的标题参数设置为PHP页面:

header('Content-Type: application/vnd.ms-excel; charset=UTF-8;'); header('Content-Disposition: attachment;filename='.$document); header('Cache-Control: max-age=0'); 

该文件将在模式alert(打开/保存)直接打开。但是,如果我有文件的名称(test.xls),我怎么可以设置标题参数打开它在页眉?

让我们说:一个名为'test.xls'的文件,我想输出一个PHP页面来打开/保存这个文件

 $file='/temp/test.xls';// file existed and created previously. header('Content-Type: application/vnd.ms-excel; charset=UTF-8;'); header('Content-Disposition: attachment;filename='.$file); header('Cache-Control: max-age=0'); 

怎么做呢?

  1. 如果文件是公开可用的,你可以简单地redirect到它:

     header('Location: /path/to/file.xls'); 
  2. 否则,只需发送你已经拥有的头文件并输出文件:

     echo file_get_contents('file.xls');