LanTianYou

[本文出自天外归云的博客园]

在一台服务器上临时起个web服务,读取服务器上的cfs文件内容并显示在页面上,做一个简单的web请求处理。

首先找到apache,在conf文件夹下vi httpd.conf,然后/DocumentRoot,快速查找DocumentRoot的位置:

然后在这个位置创建一个index.php文件,就可以处理web请求了。内容例如:

<html>
<?php
$path = $_GET["path"];
$dir = "/cfs";
$file_path = $dir.$path;
if (file_exists($file_path))
{
    $file_handle = fopen($file_path, "r");
    while (!feof($file_handle)) {
        $line = fgets($file_handle);
        echo $line;
        echo \'</br>\';
    }
    close($file_handle);
} else {
    echo "File ".$file_path." not found.";
}
?>
</html>

在conf文件夹下vi httpd.conf可以查到服务监听的ip和端口号,然后通过访问http://ip:port就可以访问服务了。如上例就是访问:http://ip:port/?path=xxxxx/xx/xxx/xx

 

分类:

技术点:

相关文章:

  • 2021-06-23
  • 2021-10-26
  • 2022-01-05
  • 2021-04-09
  • 2022-01-02
  • 2021-12-18
  • 2021-11-13
  • 2021-06-04
猜你喜欢
  • 2022-01-31
  • 2021-10-10
  • 2021-04-27
  • 2021-11-01
  • 2022-02-12
  • 2021-11-03
相关资源
相似解决方案