首页 > 解决方案 > 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 代码:

看图片-> https://imgur.com/gallery/GCqUgQh

标签: php

解决方案


问题是无法识别 php,因此您看到的是源代码而不是执行 php 代码的结果。

  1. 你在你的机器上安装了 php 吗?

    apt install php libapache2-mod-php

  2. 您是否使用 .php 扩展名命名文件?


推荐阅读