[RESOLVED] Best way to check whether a file is file or directory when using FTP
I have to loop through a list of directories to look for a file, but I cannot use the filesystem functions because the list is retrieved from an FTP connection and a priori I wouldn't have to know the real path to the file. So, I use ftp_nlist to retrieve an array with all the directories within a relative path, but I only want to do something with the subdirectories: to check whether a file exists within any of them (just one level deep needed), and discard the files and current or parent directories.
As far as I know I cannot use functions like is_dir nor is_file nor file_exists because I can't get the real path (both absolute and relative) to them. I thought on using ftp_size but I'm not sure if it's ok and if there's a better way.
Any suggestions appreciated.
You could try adding the -F flag, which if it works will append a "/" to the end of directory names (and may append "*" to end of executables).
Alternatively you could use ftp_rawlist() instead, and parse the the beginning of each entry where it lists the file type and permissions info.
$contents = ftp_list($ftp, '-F relative/directory');
I won't guarantee, however, that you'll get the same results from different target hosts.
I will try those options. Thanks a lot!
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)