【发布时间】:2015-03-09 05:08:39
【问题描述】:
我想在我的网站上包含一个文本框,它将在我的 linux 框中搜索包含输入文本的任何文件。
当我“提交”时,文本框输出...“www.website.com/file_finder.php?name=samba”.. 接下来,调用“file_finder.PHP”文件... PHP文件应该在linux框中输入“./file_finder smaba”来运行“file_finder”....
在 CLI 中手动输入“./file_finder samba”就可以了。它会在其中找到带有“samba”的文件。
但是,单击文本上的提交不会输出基于输入内容的搜索。 IT 输出基于上次在命令行手动运行“file_finder”的时间????
- 输入“./file_finder fstab”
- bash 输出所有带有“fstab”的文件
- 转到网站,在文本框中输入“samba”并点击提交
- php echo 语句 #1 输出“samba”
- php echo 语句#2 输出“./file_finder samba”
- 网站改为输出带有“fstab”的文件列表?!?!?
知道为什么它不起作用??
file_finder.php:
<?php
echo $_GET['name']."<br>";
$nname=$_GET['name'];
$shline = "./file_finder " .$nname."";
echo $shline;
$output = shell_exec($shline);
echo "<pre>$output</pre>";
?>
file_finder:
#!/bin/bash
find -L /var/www/htdocs/ -type f -iname "*"$1"*" -exec basename {} \; > /var/www/htdocs/flr_logs/finder_list.log
sort -k +1 /var/www/htdocs/flr_logs/finder_list.log >> /var/www/htdocs/flr_logs/finder_sorted.log
cat /var/www/htdocs/flr_logs/finder_sorted.log
【问题讨论】:
-
$nname=escapeshellarg($_GET['name']);// 非常重要 -
"*"$1"*"应该和"*$1*"同等重要