所以我有生成file.txt
的代码<?php
$myfile = fopen("test.txt", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
$txt = "Jane Doe\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
然后我在textarea上显示它:
<textarea rows="5" cols="50">
<?php
$file = file_get_contents('./test.txt', FILE_USE_INCLUDE_PATH);
echo $file;
?>
</textarea>
我需要使用php中的按钮直接打印文件test.txt。我怎么能在php / laravel框架中这样做?感谢
答案 0 :(得分:0)
1 而不是显示textarea,只显示一个链接:
<a href="print_test_txt.php">print text.txt!</a>
2 创建一个名为 print_test_txt.php 的新文件,并使用此php填充
第3 强>
<?php
$file = file_get_contents('./test.txt', FILE_USE_INCLUDE_PATH);
echo $file;
?>
将其输出到屏幕,以便用户可以打印它。如果您希望打印到已知的打印机,请参阅此解决方案: