我有一个HTML选择形式填充在我的数据库中发现,像这样的元素我的名单:中PHP下载的文件内容显示HTML表单
<form action="" method="POST">
<select name="item_select">
<?php
$query = "SELECT * FROM files_table";
$result = mysql_query($query);
while ($row = mysql_fetch_object($result)) {
?>
<option value=<?php echo $row->id; ?> > <?php echo $row->file_name; ></option>
<?php }// end while?>
</select>
<br /><br />
<input name="show_png" type="submit" value="Show" />
<input name="delete" type="submit" value="Delete" />
<input name="download_text" type="submit" value="Download .txt File" />
<input name="download_image" type="submit" value="Download .png File" />
</form>
我有一个“显示”功能和“删除”按钮显示和删除存储在数据库中的内容的表单。但是,我很难找出让用户下载文件的方法。现在,我的基本策略是这样的:
if (isset($_POST['download_text'])) {
// Code to create .txt file from content (omitted).
// File name of content stored in $file_name variable.
// Download file.
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="sample.txt"');
readfile($file_name);
}
这类作品。我的意思是我下载了一个包含内容的文件,但是有什么不对?我也看到这个内容后面的纯文本格式的html表单。有没有办法确保这个不出现?
你先生,是男人之间的王。谢谢! – 2012-03-21 14:33:38