[英].txt File not showing up in Bootstrap modal using PHP's file I/O methods
My current issue is that when a link is clicked in a table, the modal that gets triggered does not display a .txt file given in the PHP code. 我当前的问题是,在表中单击链接时,触发的模式不会显示PHP代码中给出的.txt文件。 The PHP statement is nested in the HTML
<p>
and <pre>
paragraph statement and uses the fopen
and fread
methods. PHP语句嵌套在HTML
<p>
和<pre>
段落语句中,并使用fopen
和fread
方法。 The code, once executed, only shows an empty box. 该代码一旦执行,将仅显示一个空框。
<div id=<?php echo "$id"; ?> class="modal fade" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header"><button aria-hidden="true" class="close"data-dismiss="modal" type="button">×</button>
<h4 class="modal-title"><?php echo "$first_name $last_name"; ?></h4>
</div>
<div class="modal-body"><img src="empty_profile.gif" width="200px" height="200px" alt="Pic goes here"><br>
<a href="mail goes here" target="_blank"><i class="fa fa-envelope"></i> Mail</a>
<p>
<pre>
<?php
$file = fopen("358.txt", "r") or die("txt not found!!1");
$read=fread($file);
echo "$read";
fclose($file);?>
</pre>
</p>
</div>
The best place for the PHP file i/o, in my opinion, is inside the "modal-body" class div, as the format structure of the modal would only allow for it to be right after the header. 我认为,PHP文件I / O的最佳位置是在“模态主体”类div内,因为模态的格式结构只允许它位于标头之后。 How can I get the file contents to show in my modal?
如何获取文件内容以模态显示?
You're using fread
incorrectly (you're missing the length
argument). 您错误地使用了
fread
(缺少length
参数)。
Instead, do as the documentation suggests and use file_get_contents
instead... 而是按照文档中的建议进行操作,而改用
file_get_contents
...
Note :
注意事项 :
If you just want to get the contents of a file into a string, usefile_get_contents()
as it has much better performance than the code above.如果只想将文件的内容转换为字符串,请使用
file_get_contents()
因为它的性能比上面的代码好得多。
For example 例如
<pre>
<?= is_readable('358.txt') ? file_get_contents('358.txt') : 'txt not found!!1' ?>
</pre>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.