'Notice: Undefined index: extension in C:\filemanager\files\index.php on line 109' and it also displays
below the name of the newly created directory 'Array ( [0] => 1 ) '
The index.php file is
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>File Manager</title>
<link rel="stylesheet" type="text/css" href="../layout.css" />
</head>
<body>
<div id="filemanager">
<h1>Your files</h1>
<form method="post" action="index.php">
<?php
global $aDir;
function copyName($i, $filename, $path) {
if (file_exists($path . $i . "_" . $filename)) {
$i++;
return copyName($i, $filename, $path);
} else {
return $path . $i . "_" . $filename;
}
}
$path = dirname($_SERVER['PATH_TRANSLATED']) . "/";
$dir_handle = @opendir($path) or die("Unable to open $path");
if (isset($_POST["btnDelete"]) && isset($_POST["filename"] )) {
if (file_exists($path . $_POST["filename"])) {
unlink($path . $_POST["filename"]);
echo "<p>The file has now been deleted.</p>\n";
}
} elseif (isset($_POST["btnCopy"]) && isset($_POST['filename']) ) {
if (file_exists($path . $_POST['filename'])) {
$newfile = copyName(1, $_POST['filename'], $path);
copy($path . $_POST['filename'], $newfile);
echo "<p>The file has now been copied.</p>\n";
}
} elseif (isset($_POST['btnMove'] ) && isset($_POST['filename']) && isset($_POST["move-directory"] )) {
$newpath = $path . $_POST["move-directory"] . "/";
if(file_exists($newpath . $_POST['filename'])) {
$newfile = copyName(1, $_POST['filename'], $newpath);
} else {
$newfile = $newpath . $_POST["filename"];
}
rename($path . $_POST["filename"], $newfile);
}
echo "<ul id=\"files\">";
while ($file = readdir($dir_handle)) {
$path_parts = pathinfo("$path/" . $file);
$ext = $path_parts["extension"];
if($file == "." || $file == ".." || $file == "index.php" )
continue;
if ($ext == "txt") {
$icon = "txt.gif";
} elseif ($ext == "php" || $ext == "html" || $ext == "htm") {
$icon = "web.gif";
} elseif ($ext == "doc") {
$icon = "word.gif";
} elseif ($ext == "jpg" || $ext == "gif") {
$icon = "img.gif";
} elseif ($ext == "pdf") {
$icon = "pdf.gif";
} elseif ($ext == "") {
$icon = "dir.gif";
} else {
$icon = "txt.gif";
}
if ($icon == "dir.gif") {
$dir = $path_parts["basename"];
$aDir[]=$dir;
echo "<li><img src=\"../img/" . $icon . "\" alt=\"\" /> <a href=\"" . $dir . "\">" . $dir . "</a></li>\n";
} else {
echo "<li><input type=\"radio\" name=\"filename\" value=\"" . $file . "\" /> <img src=\"../img/" . $icon . "\" alt=\"\" /> <a href=\"" . $file . "\">" . $file . " </a></li>\n";
}
}
closedir($dir_handle);
echo "</ul>";
print_r($aDir);
?>
<p><input type="submit" name="btnDelete" value="Delete file" /> <input type="submit" name="btnCopy" value="Copy file" /> <input type="submit" name="btnMove" value="Move to" />
<select name="move-directory">
<option value="">Select directory</option>
<?php
for ($i=0; $i < count($aDir); $i++) {
echo "<option value=\"" . $aDir[$i] . "\">" . $aDir[$i] . "</option>";
}
?>
</select></p>
</form>
<p class="nav"><a href="../index.php">Main menu</a> | <a href="../upload.php">Upload a file</a> | <a href="../createdir.php">Create a new directory</a></p>
</div>
</body>
</html>and the createdir.php is
Code: Select all
<?php
global $dirfail;
if (isset($_POST["btnCreate"])) {
//echo 'button clicked';
$newDir = isset($_POST['dirname']);
$dirpath = "/filemanager/files/" . $newDir;
if (! @mkdir($dirpath, 0777)) {
$dirfail = true;
} else {
copy("/filemanager/tmp/index.php", $dirpath . "/index.php");
header("Location: files/index.php");
}
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>File Manager - Create a new directory</title>
<link rel="stylesheet" type="text/css" href="layout.css" />
</head>
<body>
<div id="filemanager">
<h1>Create a new directory</h1>
<?php if ($dirfail == 'true') {?>
<p><strong>There was a problem creating this directory please try again.</strong></p>
<?php } ?>
<form method="post" action="createdir.php">
<p><label for="dirname">Name your directory</label>
<br /><input type="text" name="dirname" id="dirname" /></p>
<p><input type="submit" name="btnCreate" id="btnCreate" value="Create Directory" /></p>
</form>
</div>
</body>
</html>