使用PHP / laravel打印生成的文件.txt


print generated file.txt using php / laravel

所以我有了生成文件。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>

我需要打印文件test.txt直接使用按钮在php。我怎么能做到这一点在php/laravel框架?由于

1不显示文本区,只显示链接:

<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;
?>

将它输出到屏幕上,以便用户可以打印它。如果您希望打印到已知的打印机,请参阅以下解决方案:

直接打印