I know this is quite a generic question, I was hoping it could stay open so I can try to improve my styles.Basically, I have an application that connects to LDAP, performs searches, and produces a text file of results based on these searches. It then uploads the resulting text file to a server using FTP.I have an Ldap folder, and in it I have all my classes for LDAP operations. I then have an Ftp folder with my FTP classes. Lastly I have a Config folder with my config class.Because index.php receives the results of the LDAP search and I have to loop everything to get to where I need to be, I have found that index.php has got quite a lot of code within it. Is this ok?I have removed a lot of the code, but the basic structure is this<?phprequire_once __DIR__ . '/vendor/autoload.php';$config = new CONFIG\Config();$ldap = new LDAP\Ldap();$userData = array();$userArray = array();$disData = array();$disArray = array();if(performLdapOperations()) {    performFtpOperation();}function performLdapOperations() {    global $ldap, $config, $userData, $userArray, $disData, $disArray;    $ldapconn = $ldap->connect($config::LDAP_CONNECTION);    ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);    ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);    if ($ldapconn) {        try {            $ldapbind = $ldap->bind($config::LDAP_RDN, $config::LDAP_PASSWORD);            if ($ldapbind) {                $search = $ldap->search($config::LDAP_TREE_USERS, (cn=*));                $result = $search->getAllEntries();                $fp = fopen('output.txt', 'w');                /* Do a load of searching and array filling                  *  Lots of for loops and looping over the search results                 */                fclose($fp);                $ldap->close();                return true;            } else {                echo LDAP bind failed...;                return false;            }        } catch(\LDAP\LdapException $e) {            die(Exception:  . $e);        }    }}function performFtpOperation() {    global $config;    try {        $ftp = new FTP\FtpClient();        $ftp->connect($config::FTP_SERVER);        $ftp->login($config::FTP_USER, $config::FTP_PASSWORD);        $ftp->putAll('outputs', '/test');    } catch (Exception $e) {        echo 'Error: ', $e->getMessage();    }}Does this generally look ok? My main question refers to the if statement above the first function. Basically, it should only upload a file if a file has been successfully produced within the performLdapOperations function. So is doing what I do there going to ensure this is the case?Really just looking for pointers as to ways I can improve things.  Although I do not show it above, where the comment is in the first function I have many foreach loops which go through results contained within multi-dimensional arrays, so it is a lot of code.  Also, it is the ldap->bind function that throws the LdapException, so should I only wrap this in a try/catch or the whole thing like I have?
Uploading LDAP search results to an FTP server
php;error handling;ldap;ftp