Example #1
0
 }
 if ($good) {
     $filename = "data/clients_" . time() . ".csv";
     if (!move_uploaded_file($_FILES['file']['tmp_name'], $filename)) {
         ShowError("Unable to move uploaded file.");
     } else {
         $handle = @fopen($filename, "r");
         if ($handle) {
             // we are working with a lot of data here
             // we rarely update the client list, this should be fine
             ini_set("memory_limit", "512M");
             // mark all current clients as inactive
             Client::SetAllInactive();
             $database->beginTransaction();
             // get the usernames of all the current clients
             $usernames = Client::GetUsernames();
             // for faster lookup
             $usernames_fast = array();
             foreach (array_values($usernames) as $v) {
                 $usernames_fast[$v] = 1;
             }
             while (($line = fgets($handle)) !== false) {
                 if (strpos($line, "#") === 0) {
                     continue;
                 }
                 $data = explode(",", $line);
                 $done = false;
                 $username = CleanString($data[1]);
                 if (isset($usernames_fast[$username])) {
                     // update current client
                     Client::EditByUsername($username, $data[0], $data[2], $data[3], $data[4]);