curt22 Posted February 17, 2007 Share Posted February 17, 2007 I have a script that lists all the files/directorys in an ftp directory using a for loop and It works but i want it to say (file) beside files and (directory) beside directorys, I tried using is_dir($files[$i]) but it did not work how can i check if something is a file or a directory over ftp. If it helps Im using windows and php 5. ??? Link to comment https://forums.phpfreaks.com/topic/38958-solved-checking-if-a-something-is-a-directory-or-a-file-over-ftp/ Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 http://us2.php.net/file_exists http://us2.php.net/manual/en/function.is-file.php http://us2.php.net/manual/en/function.is-dir.php Link to comment https://forums.phpfreaks.com/topic/38958-solved-checking-if-a-something-is-a-directory-or-a-file-over-ftp/#findComment-187463 Share on other sites More sharing options...
curt22 Posted February 17, 2007 Author Share Posted February 17, 2007 Thanks sspoke. i tried using is_file but i can't get it to work right this is what it outputs: New Folder (this should be false) bool(false) New folder 2 (this should be false) bool(false) Untitled-1.php (this should be true) bool(true) Untitled-2.html (this should be true) bool(false) Untitled-3.php (this should be true) bool(false) test.txt (this should be true) bool(false) test2.txt (this should be true) bool(false) test3.txt (this should be true) bool(false) tree[1].html (this should be true) bool(false) Link to comment https://forums.phpfreaks.com/topic/38958-solved-checking-if-a-something-is-a-directory-or-a-file-over-ftp/#findComment-187537 Share on other sites More sharing options...
sspoke Posted February 18, 2007 Share Posted February 18, 2007 dam man I dont know but Ok i gues this will bump the topic to the top Link to comment https://forums.phpfreaks.com/topic/38958-solved-checking-if-a-something-is-a-directory-or-a-file-over-ftp/#findComment-187596 Share on other sites More sharing options...
curt22 Posted February 18, 2007 Author Share Posted February 18, 2007 Thanks everbody for your help I got it to work. In case it helps someone else here is the code: <?php // connect $conn = ftp_connect("curtis.ifastnet.com") or die("Could not connect"); // login ftp_login($conn,"curtis","******"); // get contents in array $path = "."; $contents = ftp_nlist( $conn, "-dF " . $path ); //convert to a string $files_list = implode("'", $contents); echo "<ul> Current files in directory "; echo ftp_pwd($conn); // echo files in bullet list $files = explode("'", $files_list); for($i = 0; $i < count($files); $i++) { if (substr( $files[$i], -1) == "/" ) { $files[$i] = str_replace( "/", " ", "$files[$i]") ; $files[$i] = trim($files[$i]); echo "<li>$files[$i] (directory)</li>"; } else { echo "<li>$files[$i] (file)</li>"; } } echo '</ul>'; ftp_close($conn); ?> Link to comment https://forums.phpfreaks.com/topic/38958-solved-checking-if-a-something-is-a-directory-or-a-file-over-ftp/#findComment-188191 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.