我有一个带有表格的站点,并希望在每个tr
. 单击按钮应弹出下载对话框(保存文件),然后按“保存”,下载文件。
我经常看到这种情况,但仍然不知道该怎么做。我已经通过表单设置了按钮:
<form method="get">
<input type="submit" value="<?php echo $paket; ?>" name="download" />
</form>
where$paket
包含没有.zip
结尾的文件名。
在同一个 php 文件中,就在两个require_once
语句下,我这样做了:
if ( isset( $_GET['download'] ) ) {
$name = $_GET['download'];
header( 'Content-Disposition: attachment; filename = '.$name.'.zip' );
header( 'Content-type: application/zip' );
}
如果我按下按钮,我会收到以下错误:
Warning: Cannot modify header information - headers already sent by (output started at /is/lib/require.req:154)
我知道标题信息需要放在最上面,但是require_once
如果require_once
后面几行,我应该如何使用我包含的函数?
有没有我找不到的不错(且万无一失)的教程?