У меня к Вам есть большая просьба. У меня есть скрипт, который читает директории, генерирует список этих директорий, по ним можно ходить. Зайдя в папку, можно увидеть список файлов в этой папке. Потом файл можно отредактировать.
Так вот проблема. Этот скрипт прекрасно работал на сервере IS на системе Windows2000. Теперь я меня хостинг под Apache+Unix. Так вот, скрипт некорректно работает. Читает только ту директорию, в которой лежит сам скрипт.
Специалисты по ПХП, помогите пожалуйста.
Кидаю код самого скрипта.
<?php
#chdir ($dir);
$base = \'.\'; // прописываем здесь папку
$handle=opendir($base);
if (!empty ($dir)) $namedir = $dir;
else $namedir = "First!";
while ($file = readdir($handle))
{
//Отсеиваем директорию от файлов и формируем массив директорий и файлов
$detect = is_file($file);
if ($detect == 1) $ary_file_name[] = $file;
else $dirs[] = $file;
}
echo "<title>File Editor</title><meta http-equi\\"Content-Type\\" content=\\"text/html; charset=windows-1251\\"><body bgcolor=#ECFAFF>";
echo "Dir list:
";
if (!empty($dir))
{
for ($i=2; $dirs[$i]; $i++) echo "[<a href=\\"?dir=$dir/$dirs[$i]\\"> $dirs[$i]</a>]" ;
}
else {
for ($i=2; $dirs[$i]; $i++) echo "[<a href=\\"?dir=$dirs[$i]\\"> $dirs[$i]</a> ] " ;
}
if (!empty ($dir)) { echo " <a href=\\"$PHP_SELF\\"> [Back]</a>"; }
else echo "Back";
echo "
Current directory <font color=red><b>$namedir</b>:</font>
";
echo "
Change file from list:
";
echo "<form action=\'$PHP_SELF\' method=\'POST\'>\\n<select name=\'file_name\'>\\n";
$num_files = count($ary_file_name);
for($file=0; $file<$num_files; $file++)
echo "<option value=\'$ary_file_name[$file]\'>$ary_file_name[$file]\\n";
echo "<input type=hidden name=dir value=$dir>\\n";
echo "</select><input type=\'submit\' value=\' Edit \'></form>\\n";
$app_name = \'\';
// save variables to file
if($form_submit)
{
//chdir
$fp = @fopen($file_name, \'w\')
or die("Cannot open <b>$file_name</b> for rec!");
fwrite($fp, "");
fwrite($fp, stripslashes($other)."\\n");
$num_vars = count($var_name);
for($line=0; $line<$num_vars; $line++)
{
fwrite($fp, $var_name[$line]."\\t= ");
$var_val[$line] = ereg_replace("\\r\\n", " ", $var_val[$line]);
if(! is_numeric($var_val[$line]) && ereg("^[^\\"\\\']{1,1}|^$", $var_val[$line]))
fwrite($fp, "\\"".stripslashes($var_val[$line])."\\";");
else
fwrite($fp, stripslashes($var_val[$line]).";");
if($var_cmt[$line])
fwrite($fp, "\\t//".str_replace(";", "", stripslashes($var_cmt[$line])));
fwrite($fp, "");
}
fwrite($fp, "");
fclose($fp);
$msg = "<h3>File <b>$file_name</b> written!</h3>";
}
echo "<html>\\n";
echo "<head><title>$app_name</title></head>\\n";
echo "<style>\\n";
echo "td {font-family: Verdana; font-size: 13}\\n";
echo "body {font-family: Verdana; font-size: 13}\\n";
echo "input {font-family: Verdana ; font-size: 12}\\n";
echo "</style>\\n";
echo "<body><h1>$app_name</h1>\\n";
echo $msg;
if($file_name)
{
// read variables + data into arrays
///////////////////////////////////////
$ary_file = file($file_name);
$num_lines = count($ary_file);
$var_line = 0;
for($file_line=0; $file_line<$num_lines; $file_line++)
{
$line_content = $ary_file[$file_line];
if(ereg(\'^\\$.+;\', $line_content))
{
$eq_pos = strpos($line_content, \'=\');
$sc_pos = strrpos($line_content, \';\');
$cmt_pos = strpos($line_content, \'//\', $sc_pos);
$ary_parsed[$var_line][0] = trim(substr($line_content, 0, $eq_pos));
$ary_parsed[$var_line][1] = trim(substr($line_content, $eq_pos+1, $sc_pos-$eq_pos-1));
if($cmt_pos)
$ary_parsed[$var_line][2] = trim(substr($line_content, $cmt_pos+2, strlen($line_content)-$cmt_pos));
$var_line++;
}
elseif(ereg("[^(\\n|<\\?|\\?>)]", $line_content))
$ary_other[] = $line_content;
}
// print edit form
/////////////////////
$num_vars = count($ary_parsed);
$num_xtra = count($ary_other);
echo "<form action=\'$PHP_SELF\' method=\'Post\'>\\n";
echo "<input type=\'hidden\' name=\'file_name\' value=\'$file_name\'>\\n";
echo "<table border=0 cellpadding=2 cellspacing=2 width=100%>\\n";
echo "<tr bgcolor=\'#DDDDDD\'>\\n<td colspan=3><font color=black size=3><b>File:</b></font><b><font color=red size=2> $file_name</font></b></td></tr>\\n";
for($row=0; $row<$num_vars; $row++)
{
$var_orig = $ary_parsed[$row][0];
$var_name = $ary_parsed[$row][0];
$var_name = str_replace("_", " ", ucfirst(str_replace("\\$", "", $ary_parsed[$row][0])));
$var_val = $ary_parsed[$row][1];
$use_textarea = (! is_numeric($var_val)) ? 1 : 0;
$var_cmt = $ary_parsed[$row][2];
$bgcolor = ($row % 2) ? \'#EEEEEE\' : \'#DDDDDD\';
echo "<tr bgcolor=\'$bgcolor\'><td valign=\'top\'>$var_name<input type=\'hidden\' name=\'var_name[]\' value=\'$var_orig\'></td><td valign=\'top\'>\\n";
if($use_textarea)
echo "<textarea rows=1 cols=30 name=\'var_val[]\' wrap=\'virtual\'>$var_val</textarea>\\n";
else
echo "<input type=\'text\' size=30 name=\'var_val[]\' value=\'$var_val\'>\\n";
echo "</td><td valign=\'top\'><input type=\'text\' size=30 name=\'var_cmt[]\' value=\'$var_cmt\'></td></tr>\\n";
}
// print non variables in a text area
////////////////////////////////////////
if($num_xtra)
{
echo "<tr bgcolor=\'#DDDDDD\'><td colspan=3>";
echo "<textarea rows=25 cols=20 name=\'other\' style=\'width: 100%\' wrap=\'virtual\'>";
for($row=0; $row<$num_xtra; $row++)
echo $ary_other[$row];
echo "</textarea></td></tr>";
}
echo "<tr bgcolor=\'#CCCCCC\' colspan=3><td colspan=3>\\n";
echo "<input type=\'submit\' name=\'form_submit\' value=\' Save \'>\\n";
echo "<input type=\'hidden\' name=dir value=$dir>\\n";
echo "<input type=\'reset\' value=\' Reset \'>\\n";
echo "</td></tr></table></form>\\n";
}
echo "</body></html>\\n";
echo "<form action=\'$PHP_SELF\' method=\'POST\'>\\n";
echo "<input type=\'text\' name=make value=\'\' size=\'20\'>\\n";
echo "<input type=\'hidden\' name=dir value=$dir >\\n";
echo "<input type=\'submit\' value=\'Create file\'>\\n";
$dmade = date(\'Y/m/d H:m:s\');
if (!empty($make)) {$f = fopen($make,"a"); fputs($f,"Ñîçäàí -- $dmade",4096); fclose($f);
echo "<font color=blue>File with name <b> $make</b> ñîçäàí!</font>"; }
else ;
?>
<style>
body {font-family: Verdana;font-size: 12px;}
a:link {font-family: Verdana; color: blue; font-size: 12px; text-decoration: none;}
a:visited {font-family: Verdana; color: blue; font-size: 12px; text-decoration: none;}
a:active {font-family: Verdana; color: blue; font-size: 12px; text-decoration: none;}
a:hover {font-family: Verdana; color: black ; font-size: 12px; text-decoration: underline; }
.in, Input, Textarea, Select {border-style: solid; border-width: 1; font-family: Verdana; color: black; font-size: 12px;}
.bt, Buttons {border-color: white; background: white; color: white; font-size: 12px;}
.gb {border-style: solid; border-width: 1; font-family: Verdana; color: #9999CC; font-size: 12px;}
.fnt {background-color: #aaaacc;}
</style>