美好的一天所有人 好的,所以我尽我所能做了很多,需要一些指导和帮助。目前我对html/php很新,所以请耐心等待。计划是在下拉列表中列出来自Dir的文本文件,这是我已经完成的工作,现在我想在提交按钮按下时在表格的同一页中显示文本文件。这是我到目前为止,任何输入欢迎,因为我仍然在学习! bash脚本只是一个grep函数,用于从原始文件中获取特定行并将其复制到/ tmp。 再次感谢提交按钮后,在html页面显示选定的文本文件
<html>
<head>
<title>Data Request</title>
</head>
<body>
<h1 align="center">Dispatch Report</h1>
<h2 align="center">Wrong Arrives Report</h2>
<table align="center" border="2">
<tr>
<td>Select Shift<br>
<form name="shiftfrm" id="shiftfrm">
<select name="shiftlist" id="shiftlist">
<option value="" selected="selected">--------</option>
<?php
$dir = opendir ("/var/www/files/");
while (false !== ($file = readdir($dir))) {
if (strpos($file, '.txt',1)) {
echo '<option value="' . $file . '">' . $file . '</option>';
}
}
?>
</select>
<input type="submit" id="submit" value="Submit"/>
<?php
if(($handle = fopen('/tmp/sh130418n.txt', 'r')) !== false)
{
$output = '<table align="center" width="" border="2">';
while(($data = fgetcsv($handle)) !== false)
{
$output .= '<tr>';
foreach($data as $value)
{
$output .= sprintf('<td>%s</td>', $value);
}
fclose($handle);
$output .= '</table>';
}
echo $output;
?>
</td></tr>
</table>
<?php
$output = exec('/var/www/cgi-bin/manualexceptget.sh');
echo "<pre>$output</pre>";
?>
</body>
</html>
。 – 2013-05-06 06:03:56
尝试对不存在的变量使用[empty](http://php.net/empty)。它会抛出一个错误。 [isset](http://php.net/isset)阻止了这一点,因为它在isset函数返回false的那一刻结束了if语句。 – Imperative 2013-05-06 06:07:02
“确定一个变量是否被认为是空的,如果一个变量不存在或者它的值等于FALSE,则该变量被认为是空的,如果该变量不存在,empty()不会产生警告。来自'empty()'的PHP手册。 http://us3.php.net/manual/en/function.empty.php – 2013-05-06 06:11:03