Hello,
I am having an issue with a script that makes a directory for my web text editor script... i get the following errors:
Warning: OpenDir: No such file or directory (errno 2) in /home/cool-pal/public_html/webedit/navigator.php on line 56
Warning: readdir(): supplied argument is not a valid Directory resource in /home/cool-pal/public_html/webedit/navigator.php on line 60
Warning: sort() expects parameter 1 to be array, null given in /home/cool-pal/public_html/webedit/navigator.php on line 62
Here Is My Script. The ERROR LINES ARE LABELED:
<?php
include "common.inc.php";
function mkdir_form() {
global $PHP_SELF, $dir;
?>
<center>
<form method="post" action="<?php echo "$PHP_SELF?action=make_dir&dir=$dir"; ?>">
<input type="hidden" name="action" value="make_dir">
<input type="hidden" name="dir" value="<?php echo $dir ?>">
<?php
echo "<strong>$dir</strong>"
?>
<br>
<input type="text" name="new_dir" size="10">
<input type="submit" value="Make Directory" name="Submit">
</form>
</center>
<?php
}
function make_dir() {
global $dir, $new_dir;
if(!@mkdir("$dir/$new_dir", 0700)) {
error_message("Cannot create the new directory $dir/$new_dir and CHMOD it 700.");
}
html_header();
dir_page();
html_footer();
}
function display() {
global $filename, $dir, $text_file_array, $image_file_array;
$extenstion = array_pop(explode(".", $filename));
if(in_array($extension, $text_file_array)) {
readfile("$dir/$filename");
}
else if(in_array($extension, $image_file_array)) {
echo "<IMG SCR=\"$dir/$filename\">";
}
else echo "Cannot be displayed. $dir/$filename has not been recognized as a text file, nor as a valid image file. ";
}
function dir_page() {
global $dir, $default_dir, $PHP_SELF, $default_filename;
if($dir = '') {
$dir = $default_dir;
}
$dp = opendir($dir); \ ERROR LINE 58
?>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<?php
while($file = readdir($dp)) $filenames[] = $file; \ ERROR LINE 60
sort($filenames); \ ERROR LINE 62
for($i = 0; $i < count($filenames); $i++)
{
$file = $filenames[$i];
if($dir == $default_dir && ($file == "." || $file == ".."))
continue;
if(is_dir("$dir/$file") && $file == ".")
continue;
if(is_dir("$dir/$file")) {
if($file == ".."){
$current_dir = basename($dir);
$parent_dir = ereg_replace("/$current_dir$","",$dir);
echo "<tr><td width=\"100%\" NOWRAP>
<a href=\"$PHP_SELF?dir=$parent_dir\">$file/
</a></td></tr>\n";
}
else echo "<tr><td width=\"100%\" NOWRAP>
<a href=\"$PHP_SELF?dir=$dir/$file\">$file/</a></td></tr>\n";
}
else echo "<tr><td width=\"100%\" NOWRAP>
<a href=\"$PHP_SELF?action=display&dir=$dir&filename=$file\" target=\"_blank\">$file</a></td></tr>\n";
}
?>
</table>
<?php
mkdir_form();
}
if(empty($dir) || !ereg($default_dir, $dir)) {
$dir = $default_dir;
}
switch ($action) {
case "make_dir":
make_dir();
break;
case "display":
display();
break;
default:
html_header();
dir_page();
html_footer();
break;
}
?>