为什么 .php 文件上的 fread() 与 .txt 文件上的 fread() 不同?
从 .php 文件读取 .txt 文件时,fread()
函数无法工作(不显示错误)是否有任何原因?
代码
$file = fopen("db.php","rw");
$data = fgets($file, filesize("db.php"));
echo($data);
fclose($file);
die();
Is there any reason why the fread()
function wouldn't work (no errors show up) when reading from a .php file over a .txt file?
code
$file = fopen("db.php","rw");
$data = fgets($file, filesize("db.php"));
echo($data);
fclose($file);
die();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,如果您以相同的方式处理它们(相同的协议/方法/位置),则不会。它们都只是
fread()
的普通数据。No, not if you're addressing them the same way (same protocol / method / location). They're all just plain data to
fread()
..php 文件和 .txt 文件的权限是否相同?我知道这似乎是显而易见的,但有时我们会忽略一些小事情。
Are the permissions the same for the .php file and the .txt file? I know that seems obvious but sometimes it's the little things that get by us.
关键是,如果您想在页面中显示它,它将被解释,因此您应该使用 FILTER_SANITIZE_SPECIAL_CHARS 或其他类似选项过滤其 html 标签。
The point is that if you want to display that in a page, it will get interpreted, so you should filter its html tags with FILTER_SANITIZE_SPECIAL_CHARS or some other similar option.