What is the recommended method to determine if an item in an array from FTP contains a file or a directory in PHP?

To determine if an item in an array from FTP contains a file or a directory in PHP, you can use the `ftp_rawlist()` function to get detailed information about each item in the directory. Then, you can check the first character of each item's permissions string to determine if it is a directory (starts with 'd') or a file (does not start with 'd').

// Connect to FTP server
$ftp_server = 'ftp.example.com';
$ftp_user = 'username';
$ftp_pass = 'password';
$conn_id = ftp_connect($ftp_server);
ftp_login($conn_id, $ftp_user, $ftp_pass);

// Get detailed listing of directory
$files = ftp_rawlist($conn_id, '/path/to/directory');

// Loop through each item and determine if it is a file or directory
foreach ($files as $file) {
    $permissions = substr($file, 0, 1);
    $name = substr($file, 56); // Adjust the index based on your FTP server's format
    if ($permissions == 'd') {
        echo $name . ' is a directory' . PHP_EOL;
    } else {
        echo $name . ' is a file' . PHP_EOL;
    }
}

// Close FTP connection
ftp_close($conn_id);