Reputation: 422
hello I have my code that connects to my ftp server
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
//ftp_mkdir($conn_id, $dir);
$contents = ftp_nlist($conn_id, $dir);
//var_dump($contents);
echo "<select name=\"file\">\n";
// Now loop through the files, echoing out a new select option for each one
if (($contents != '.') && ($contents != '..') )
{
foreach( $contents as $fname )
{
echo "<option>{$fname}</option>\n";
}
echo "</select>\n";
}
}
but the page is still echoing back the directories as . & .. despite the $contents != bit; what is missing?
changed to this ->
if (($fname != '.') && ($fname != '..') )
{
foreach( $contents as $fname )
{
echo "<option>{$fname}</option>\n";
}
echo "</select>\n";
}
}
but still same result
Upvotes: 1
Views: 296
Reputation: 898
You might want to compare $fname
inside the loop against being .
or ..
. This is probably more what you want.
Upvotes: 3