Garethp Posted October 1, 2009 Share Posted October 1, 2009 Ok, so is_file doesn't seem to work with FTP connections, any idea why? Here is my code <?php session_start(); //Connect to the FTP server $ftp = ftp_connect('xxxx'); //Login to the FTP server $login = ftp_login($ftp, 'xxxx', 'xxxx'); if(!$login) { echo "Error"; exit(); } if(!isset($_SESSION['Folder'])) { $_SESSION['Folder'] = "public_html"; } if(isset($_GET['folder'])) { $_SESSION['Folder'] .= "/" . $_GET['folder']; } $Folder = $_SESSION['Folder']; if(preg_match("~\.\.$~", $Folder)) { $Folder = preg_replace("~^(.*?)/?\.\.?$~", "$1", $Folder); $_SESSION['Folder'] = $Folder; } ftp_chdir($ftp, $Folder); if(isset($_GET['action']) && $_GET['action'] == "up") { $_SESSION['Folder'] = preg_replace("~^(.+?)/.+$~", "$1", $_SESSION['Folder']); ftp_cdup($ftp); } $List = ftp_nlist($ftp, ""); unset($List[array_search('.', $List)]); unset($List[array_search('..', $List)]); natcasesort($List); echo "<a href=\"?action=up\">Parent Folder</a><br><br><b>Folders</b><br>"; foreach($List as $v) { if(is_file($v)) { continue; } echo "<a href=\"?folder=$v\">$v</a><br>"; } echo "<br>"; echo "<b>Files</b><br>"; foreach($List as $v) { if(!is_file($v)) { continue; } echo $v . "<br>"; } echo "<br>"; ftp_close($ftp); ?> With this code, I only get index.php as a file, and everything else as a folder. However, if I use is_dir instead, it works. Why is this? Link to comment https://forums.phpfreaks.com/topic/176190-ftp-is_file/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.