Sorry, did not test this before submitting it.
Here is the updated script. I did test this one and it worked like a charm.
chad.
<?php
// quick "die" function
function funk_die($msg) {
if($msg=='normal') {
return "<html><body><a href=\"ftp.php\">back</a></body></html>";
}
}
// function to give dir listing stuff
function dir_funk () {
// cookie?
global $ftp;
// dir name
$dir=ftp_pwd($ftp);
// dir listing array
$dirlist=ftp_rawlist($ftp,$dir);
// print the directory listing
$funk = "<html><body><p>current directory: <b> $dir </b></p>";
$funk .= "<p><a href=\"ftp.php?&updir=$dir\">go up one level</a>
</p>";
$funk .= "<p>
<table cellspacing=0 cellpadding=2 border=1>
<tr><td><b>permissions</b></td><td><b>file/directory</b></td>
<td><b>download</b></td><td><b>delete</b></td>
<td><b>chmod</b></td><td><b>rename</b></td>
</tr>
";
while(list($i,$thingy)=each($dirlist)) {
$thingy=preg_replace("/\s+/", " ", $thingy);
if($i==0) {
echo "";
} else {
list($chmod,$thing,$owner,$group,$size,$month,$day,$time,$filename)=explode(" ",$thingy);
if(ereg("d",$chmod)) {
$funk .= "<tr><td>$chmod</td><td><a href=\"ftp.php?dir=$dir/$filename\">$filename</a></td>
<td>dir</td>
<td><a href=\"ftp.php?delete=dir&thingy=$dir/$filename\">delete</a></td>
<td><a href=\"ftp.php?chmod=1&thingy=$dir/$filename\">chmod</a></td>
<td><a href=\"ftp.php?rename=$dir/$filename\">rename</a></td>
</tr>";
} else {
$funk .= "<tr><td>$chmod</td><td>$filename</td>
<td><a href=\"ftp.php?dl=1&file=$dir/$filename\">d/l ($size)</a></td>
<td><a href=\"ftp.php?delete=file&thingy=$dir/$filename\">delete</a></td>
<td><a href=\"ftp.php?chmod=1&thingy=$dir/$filename\">chmod</a></td>
<td><a href=\"ftp.php?rename=$dir/$filename\">rename</a></td>
</tr>";
}
}
}
$funk .= "</table>
</p>";
$funk .= "<p>Create a new directory<br>
<form action=\"ftp.php\" method=\"POST\">
<input size=\"15\" name=\"name\">
<input type=\"hidden\" name=\"current_dir\" value=\"$dir\">
<input type=\"submit\" name=\"newdir\" value=\"create_dir\">
</form>
</p>";
$funk .= "<p>Upload a local file<br>
<form action=\"ftp.php\" method=\"POST\" enctype=\"multipart/form-data\">
<input type=\"file\" name=\"localfile\"><br>
<input type=\"hidden\" name=\"current_dir\" value=\"$dir\">
<input type=\"submit\" name=\"upload\" value=\"upload_file\">
</form>
</p>";
$funk .= "</body></html>";
return $funk;
}
if(!$login) {
// print the login form
echo "<html><body><p><b>ftp login</b><hr></p>
<form action=\"ftp.php\" method=\"POST\">
<p>Your server (eg ftp.yoursite.com)<br> <input size=\"30\" name=\"server\"></p>
<p>Username <br> <input size=\"30\" name=\"username\"></p>
<p>Password <br> <input size=\"30\" name=\"password\"></p>
<p><input type=\"submit\" name=\"login\" value=\"login\"></p>
</form></body></html>";
} else {
// try to connect or die with an error
$ftp=ftp_connect($server) or die("invalid server"

;
// try to login or die with error
$conn=ftp_login($ftp,$username,$password) or die("login failed for some reason"

;
// set a cookie so the !$login form above is never displayed
setcookie("login","active"

;
// set goody cookies
setcookie("server",$server);
setcookie("username",$username);
setcookie("password",$password);
if($dir) {
ftp_chdir($ftp,$dir);
echo dir_funk();
} elseif($dl) {
if($get) {
if(!$local) {
die("please enter a value"

;
}
ftp_get($ftp, $local, $file, FTP_BINARY);
echo funk_die(normal);
} else {
echo "<html><body>";
echo "download file";
$size=ftp_size($ftp,$file);
$time=ftp_mdtm($ftp,$file);
$time=date("d M Y, H i",$time);
echo "<p><table cellspacing=0 cellpadding=2 border=1>
<tr><td><b>filename</b></td><td><b>size</b></td>
<td><b>date modified</b></td></tr>
<tr><td>$file</td><td>$size</td><td>$time</td></tr></table>";
echo "<form action=\"ftp.php\" method=\"POST\">
where to download the file to (/home/me/file.txt or c:/file.txt):<br>
<INPUT NAME=\"local\" size=\"40\">
<input type=\"hidden\" name=\"dl\" value=\"1\">
<input type=\"hidden\" name=\"file\" value=\"$file\"><br>
<INPUT TYPE=\"submit\" name=\"get\" VALUE=\"download file\">
</FORM>";
echo "</body></html>";
}
} elseif($rename) {
if($do) {
if(!$val) {
die("please enter a value"

;
}
ftp_rename($ftp, $rename, $val);
echo funk_die(normal);
} else {
echo "<html><body>
rename this file: $rename
<p>
<form action=\"ftp.php\" method=\"POST\">
Rename to: <input size=\"50\" name=\"val\" value=\"$rename\"><br>
<input type=\"hidden\" name=\"rename\" value=\"$rename\">
<input type=\"submit\" name=\"do\" value=\"rename\">
</form>
</body></html>";
}
} elseif($chmod) {
if($do) {
if(!$val) {
die("please enter a value"

;
}
$cmd="CHMOD $val $file";
ftp_site($ftp, $cmd);
echo funk_die(normal);
} else {
echo "<html><body>
chmod this file: $thingy
<p>
<form action=\"ftp.php\" method=\"POST\">
<input size=\"4\" name=\"val\" maxlength=\"4\"> CHMOD value<br>
<input type=\"hidden\" name=\"file\" value=\"$thingy\">
<input type=\"hidden\" name=\"chmod\" value=\"1\">
<input type=\"submit\" name=\"do\" value=\"chmod\">
</form>
</body></html>";
}
} elseif($delete) {
if($delete=='file') {
ftp_delete($ftp, $thingy);
} elseif($delete=='dir') {
ftp_rmdir($ftp, $thingy);
}
echo funk_die(normal);
} elseif($upload) {
if(!$localfile) { die("please enter a file"

; }
if(!$local_fp = fopen($localfile,"r"

) {
echo "unable to open $localfile for reading<br>\n";
exit();
}
if(eregi("application|image",$localfile_type)) {
$ftp_type = FTP_BINARY;
}
else {
$ftp_type = FTP_ASCII;
}
ftp_fput($ftp, $current_dir."/".$localfile_name, $local_fp, $ftp_type);
header("Location: ftp.php?dir=".$current_dir);
echo funk_die(normal);
} elseif($newdir) {
if(!$name) { die("please enter a name"

; }
$newdir = $current_dir . "/" . $name;
ftp_mkdir($ftp,$newdir);
echo funk_die(normal);
} elseif($updir) {
$newdir = str_replace( substr( strrchr( $updir, "/" ), 1 ) , "", $updir);
ftp_chdir($ftp,$newdir);
echo dir_funk();
} else {
echo dir_funk();
}
}
?>