php - echo 命令显示 php 文件的所有代码
问题描述
我正在学习 php,并让这些文件更改,但是 echo 命令而不是只显示字符串,而是显示文件的整个代码。
我正在使用 linux ubuntu 和 apache2。
<html>
<head>
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;margin:0px auto;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}
.tg .tg-0lax{text-align:left;vertical-align:top}
@media screen and (max-width: 767px) {.tg {width: auto !important;}.tg col {width: auto !important;}.tg-wrap {overflow-x: auto;-webkit-overflow-scrolling: touch;margin: auto 0px;}}</style>
</head>
<body>
Welcome to our awesome gallery!</br>
See recent uploaded pictures from our community, and feel free to rate or comment</br>
<?php
require '/var/www/html/lib.php';
$path = '/var/www/html/uploads/';
$ignored = array('.', '..', 'index.html');
$files = array();
$i = 1;
echo "<div class='tg-wrap'><table class='tg'>"."\n";
foreach (scandir($path) as $file) {
if (in_array($file, $ignored)) continue;
$files[$file] = filemtime($path. '/' . $file);
}
arsort($files);
$files = array_keys($files);
foreach ($files as $key => $value) {
$exploded = explode('.',$value);
$prefix = str_replace('_','.',$exploded[0]);
$check = check_ip($prefix,$value);
if (!($check[0])) {
continue;
}
-- snip --
[...]
?>
</table></div>
</body>
</html>
我不仅得到了 echo 上的字符串,还得到了 php 代码:
解决方案
问题是无法识别 php,因此您看到的是源代码而不是执行 php 代码的结果。
你在你的机器上安装了 php 吗?
apt install php libapache2-mod-php
您是否使用 .php 扩展名命名文件?
推荐阅读
- r - 使用 paste0 通过 for 循环创建多个对象名称
- django - ImportError:没有命名模块。Worker 无法启动
- android - Kotlin:如何以共享首选项删除存储在数组中的项目
- react-native - 如何使用 react-native 将数据保存在 Salesforce 帐户中?
- twitter-bootstrap - 使用 ng add 命令安装 ngx-bootstrap
- javascript - 总结 Javascript 中的替换函数
- r - install.packages() 强制不选择 CRAN 镜像?
- python - 为什么输出显示一个进程执行了多个任务
- java - .switchIfEmpty() 得到热切评估有什么意义?
- performance - 如何提高 cassandra yaml 文件性能以实现快速写入查询?