PHP File Manager
Posted: Fri Jul 15, 2005 2:51 pm
Basically, there are a few things that don't work. Once you travel beyond the main directory, everything is recognized as just a file even if its a dir. This code is extremely slow when trying to move into somewhat populated directory's and im not sure how to make it at least fast enough to actually work. Finally, it fails to get the contents of a file to the textarea in edit mode.
Code:
Live Example:
http://www.davidzworld.programmer-scrip ... r/main.php
Any help would be greatly appreciated.
Code:
Code: Select all
<?
function ftp_is_dir($conn, $dir)
{
if(@ftp_chdir($conn, $dir))
{
ftp_chdir($conn, "e;.."e;);
return true;
} else {
return false;
}
}
?>
<html>
<head>
<title>ProjectLance.net - File Manager</title>
<link rel="e;stylesheet"e; type="e;text/css"e; href="e;style.css"e;/>
</head>
<body>
<?
//LOGIN INFO
$dom="e;davidzworld.programmer-scripts.com"e;;
$domain="e;ftp.davidzworld.programmer-scripts.com"e;;
$user="e;*****"e;;
$pass="e;*****"e;;
//SET CONNECTIONS
$conn_id=ftp_connect($domain);
$login = ftp_login($conn_id, $user, $pass);
ftp_pasv ( $conn_id, true );
//DIRECTORY CONTENTS
if($_GETї"e;dir"e;]!="e;"e;)
{
$mydir=$_GETї"e;dir"e;];
} else {
$mydir="e;."e;;
}
ftp_chdir($conn_id, $mydir);
$contents = ftp_nlist($conn_id, "e;."e;);
?>
<? if($_GETї"e;mode"e;]=="e;view"e; || $_GETї"e;mode"e;]=="e;"e;) { ?>
<center>
<table width="e;800"e; cellpadding="e;2"e; cellspacing="e;0"e; style="e;border: 1px solid #000;"e;>
<tr>
<td class="e;tblHead"e;>File Manager: <i><?= $dom; ?></i></td>
</tr>
<?
$sColor="e;#6666AA"e;;
foreach($contents as $dir)
{
if(ftp_is_dir($conn_id, $dir) && $dir!="e;."e; && $dir!="e;.."e;)
{
if($sColor=="e;#6666AA"e;) { $sColor="e;#666699"e;; } else { $sColor="e;#6666AA"e;; }
echo "e;<tr>\n"e;;
echo "e;<td bgcolor='$sColor' style='border-top: 1px solid #000;'><a href='main.php?mode=view&dir=$dir'><img src='images/folder.gif' border='0'/></a> $dir</td>\n"e;;
echo "e;</tr>\n"e;;
}
}
foreach($contents as $file)
{
if(!ftp_is_dir($conn_id, $file))
{
if($sColor=="e;#6666AA"e;) { $sColor="e;#666699"e;; } else { $sColor="e;#6666AA"e;; }
echo "e;<tr>\n"e;;
echo "e;<td bgcolor='$sColor' style='border-top: 1px solid #000;'><a href='main.php?mode=edit&file=$file'><img src='images/file.gif' border='0'/></a> $file</td>\n"e;;
echo "e;</tr>\n"e;;
}
}
?>
</table>
</center>
<? } else if($_GETї"e;mode"e;]=="e;edit"e;) { ?>
<center>
<table width="e;800"e; cellpadding="e;2"e; cellspacing="e;0"e; style="e;border: 1px solid #000;"e;>
<tr>
<td class="e;tblHead"e; align="e;center"e;>Edit File: <?= $_GETї"e;file"e;]; ?></td>
</tr>
<tr>
<td bgcolor="e;#66666AA"e; align="e;center"e;>
<form action="e;main.php"e; method="e;post"e;>
<textarea name="e;FContents"e; rows="e;30"e; cols="e;70"e;>
<?
if (ftp_get($conn_id, getcwd()."e;/"e;.$file, $file, FTP_BINARY)) {
$INSIDE=file_get_contents($file);
echo nl2br($INSIDE);
} else {
echo "e;Could Not Get Contents..."e;;
}
?>
</textarea>
</form>
</td>
</tr>
<? } ?>
<?
//CLOSE CONNECTION
ftp_close($conn_id);
?>
</body>
</html>http://www.davidzworld.programmer-scrip ... r/main.php
Any help would be greatly appreciated.