HTML/PHP:单击按钮打开下载文本文件框
我试着为这个找到一些东西,但没有成功。。。我只想创建一个内容,让用户通过点击一个按钮打开一个经典下载框,将其下载到一个文本文件中 我有我的html按钮:HTML/PHP:单击按钮打开下载文本文件框,php,html,dialog,download,save,Php,Html,Dialog,Download,Save,我试着为这个找到一些东西,但没有成功。。。我只想创建一个内容,让用户通过点击一个按钮打开一个经典下载框,将其下载到一个文本文件中 我有我的html按钮: echo "<form name=\"myform\" action=\"myfile.php\" method=\"POST\" enctype=\"multipart/form-data\">"; echo "<input type=\"hidden\" name=\"phase2\" value=\"1\">";
echo "<form name=\"myform\" action=\"myfile.php\" method=\"POST\" enctype=\"multipart/form-data\">";
echo "<input type=\"hidden\" name=\"phase2\" value=\"1\">";
echo "<div class=\"siej_upload_field\"><input type=\"submit\" name=\"submit\" value=\"Save file\"></div>";
echo”“;
回声“;
回声“;
以及单击后的呼叫:
if( isset($_POST['phase2']) && $_POST['phase2']== 1)
{
$file = 'mytextfile.txt';
$content = 'content test';
$res = file_put_contents($file, $content);
echo 'result : '. $res . '<br/>';
}
if(isset($\u POST['phase2'])和&$\u POST['phase2']==1)
{
$file='mytextfile.txt';
$content='content test';
$res=文件内容($file,$content);
回显“结果:”.$res.“
”;
}
尽管我正确地进入了这个状态,但什么也没有发生。我得到这个结果:
结果:12
那怎么办呢?谢谢你的帮助…试试这个
<?php
$file = 'mytextfile.txt'; #Place of the file or the post.
if (file_exists($file))
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}
?>
我尝试了这个方法,但它没有下载文件,甚至没有显示任何弹出窗口,它只将文件内容输出到页面中。