Hi! i'm trying to add some functions to my directory script (upload files, edit files, edit directory, delete files, delete directory, and view files in a seperate window. I've search around and didn't really understand some of the tutorials I found and I'm a beginner and new to PHP, so if any one here can help out with some codes, with some explaination how it works, I would appreciate a lots....
Thanks ahead, Please help.....Below is my original code, you can modify anything you like...
MIKE
===================================
print <<<HTML
<center><br>
<table width="95%" border="0" cellspacing="0" cellpadding="2">
<tr><td height="40" bgcolor="#F2F2F2" class="tableborder"> <font size="4">FILES EXPLORER</font></td>
<tr><td><hr width="100%" noshade="noshade" color="#F2F2F2" size="1">
[ <a href="filesexplorer.php?op=browse">Files & Directories</a> ]
[ <a href="$admin_admindirurl/index.php?page=mainpage">Main Page</a> ]
<hr width="100%" noshade="noshade" color="#F2F2F2" size="1"></td></tr>
</table>
HTML;
// =============================================
// processing
// =============================================
if(isset($GET['op']) && ('browse' == $GET['op'])) {
browse();
exit;
} if(isset($GET['op']) && ($location == $GET['op'])) {
echo("view");
} else {
browse();
}
// =============================================
// browse files & directories
// =============================================
function browse() {
$path = $_GET["get"];
if (!$path) {
$path = ".";
}
if (ereg("../", $path) or ereg("/", $path) or ereg("~", $path)) {
$path = ".";
}
echo "<table width=\"95%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">
<tr><td width=\"100%\">";
$dir = str_replace("./", " : ", $path); if ($dir == "."):
echo "Root"; else:
echo "<a href=\"filesexplorer.php?op=browse\">Root</a> ".$dir; endif;
echo "</td></tr></table>";
print <<<HTML
<form method="post" action="" style="margin:0">
<input type="hidden" name="op" value="browse">
<input type="hidden" name="op" value="view">
<input type="hidden" name="href" value="$location">
<table width="95%" border="0" cellspacing="1" cellpadding="2">
<tr bgcolor="#F2F2F2">
<td width="30%" height="20"><strong>Files & Directories</strong></td>
<td width="10%" height="20"><strong>Sizes</td>
<td width="20%" height="20"><strong>Last Modified</td>
<td width="20%" height="20"><strong>Types </td>
<td width="20%" height="20"><strong>Options </td>
</tr>
</table>
HTML;
$desc['php'] = "php";
$desc['html'] = "html";
$desc['txt'] = "text";
$desc['pl'] = "perl";
$desc['jpg'] = "jpeg";
$desc['gif'] = "gif";
$desc['png'] = "png";
$desc['wsf'] = "wsf";
$desc['cgi'] = "cgi";
$dir = opendir($path);
while (false !== ($file = readdir($dir))) {
if (!is_dir("$dirpath/$file")) {
$list[] = $file;
}
}
sort($list);
while($file = @readdir($dir)) {
$list[] = $file;
}
sort($list);
for($i=0; $i<sizeof($list); $i++) {
if (is_dir($path."/".$list[$i]) == "dir") {
$list_dirs[] = $list[$i];
} elseif(is_file($path."/".$list[$i]) == "file") {
$list_files[] = $list[$i];
}
}
$list = array_merge($list_dirs, $list_files);
echo "<table width=\"95%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">";
for($i=0; $i<sizeof($list); $i++) {
$file = $list[$i];
if(ereg(".", $file) or ereg("_", $file)) { } else {
$location = "$path/$file";
$date = filemtime($path."/".$file);
$date = date("d/m/y, H:i", $date);
$type = filetype($location);
$size = filesize($location);
if ($size > 1024 and $size < 1024*1024) {
$size = $size/1024;
$size = round($size, 1)."kb";
}
if ($size > 1024*1024) {
$size = $size/1024/1024;
$size = round($size, 1)."mb";
}
$ext = substr(strrchr($file, "."), 1);
if(is_file($location)) $numfile++;
if(is_dir($location)) $numdir++;
$type = filetype($path."/".$file);
if($type == "dir") {
if(file_exists($location)) {
$href = "?op=browse&get=".$location;
} else {
$href = "?op=browse&get=".$location; // open dir
}
} else {
$href = $location; // open files
}
echo "<tr><td width=\"30%\">";
if ($type == "dir") {
echo " <img src=\"http://www.postyourweb.us/images/icons_filesexplore_folder.gif\" width=\"15\" height=\"12\" align=\"middle\">";
} else {
echo " <img src=\"http://www.postyourweb.us/images/icons_filesexplore_ext.gif\" width=\"16\" height=\"16\" align=\"middle\">";
}
print <<<HTML
<a href="$href">$file</a></td>
<td width="10%">$size</td>
<td width="20%">$date</td>
<td width="20%">
HTML;
if($type == "dir") {
echo("folder");
} else {
echo $desc["$ext"];
if(ereg('.php$', $file)) {
echo (" [ <a href=\"$path/$file\">source</a> ]");
}
}
echo "</td><td width=\"20%\"></td></tr>";
}
}
echo "<tr><td colspan=\"5\"><hr width=\"100%\" noshade=\"noshade\" color=\"#F2F2F2\" size=\"1\">
Directories: <strong>".$numdir."</strong> Files: <strong>".$numfile."</strong> </td></tr>";
echo "<tr><td colspan=\"5\"><hr width=\"100%\" noshade=\"noshade\" color=\"#F2F2F2\" size=\"1\"></td></tr></table></form><br>";
createdirs_form();
}
//=============================================
// create dirs form
//=============================================
function createdirs_form() {
print <<<HTML
<form method="post" action="?op=createdir">
<input type="hidden" name="path" value="$path">
<input type="hidden" name="file" value="$file">
<table width="95%" border="1" cellspacing="0" cellpadding="2">
<tr><td width="100%">Directory: <input type="text" name="file"> <input type="submit" value="add"></td>
</tr></table></form>
<br>
HTML;
}