在一台服务器上临时起个web服务,读取服务器上的cfs文件内容并显示在页面上,作一个简单的web请求处理。php
首先找到apache,在conf文件夹下vi httpd.conf,而后/DocumentRoot,快速查找DocumentRoot的位置:html
而后在这个位置建立一个index.php文件,就能够处理web请求了。内容例如: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/xxapache