// Delete directory if it is empty
 if ($count == 0) {
     rmdir($temp_dir);
 } else {
     $ficheros = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($temp_dir), RecursiveIteratorIterator::SELF_FIRST);
     foreach ($ficheros as $nombre => $fichero) {
         // Convert file
         if (strpos($fichero, '.txt') !== false) {
             $path_orig = $fichero;
             $path_dest = preg_replace('/(\\.txt)/', '_convert$1', $path_orig);
             $fich_orig = fopen($path_orig, "r");
             $fich_dest = fopen($path_dest, "w");
             $fich_htaccess = fopen($temp_dir . ".htaccess", "w");
             if ($fich_orig && $fich_dest && $fich_htaccess) {
                 // Print header
                 fwrite($fich_dest, Ubicacion::printHeader() . "\n");
                 // Skip first line
                 fgets($fich_orig);
                 while (($line = fgets($fich_orig)) !== false) {
                     // Process the line read
                     $id_elem = generateID();
                     $datos = explode(",", $line);
                     $lat = $datos[2];
                     $long = $datos[3];
                     $ubic = new Ubicacion($id_elem, $lat, $long);
                     $file_name = str_replace(".txt", "", $nombre);
                     fwrite($fich_dest, $ubic->__toString() . "\"" . PHP_EOL);
                 }
                 fclose($fich_orig);
                 unlink($path_orig);
                 fclose($fich_dest);
 } else {
     if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $original_file)) {
         echo "Fichero cargado correctamente.<br><br>";
     } else {
         echo "Lo sentimos, se ha producido un error subiendo el fichero.<br><br>";
     }
 }
 // >>> CREATE THE FILE =============================================================================================
 // IF user has selected a file
 if (strcmp($real_file, $target_dir) == 0) {
     unset($_FILES["fileToUpload"]);
     $file_selected = array_key_exists("fileToUpload", $_FILES);
 }
 if ($file_selected && ($fd_convertido = fopen($destination_file, "w"))) {
     if ($fd_original = fopen($original_file, "r")) {
         fwrite($fd_convertido, Ubicacion::printHeader() . "\n");
         // Skip first line
         fgets($fd_original);
         while (($line = fgets($fd_original)) !== false) {
             // process the line read.
             $id_elem = generarID();
             $datos = explode(",", $line);
             $lat = $datos[2];
             $long = $datos[3];
             $ubic = new Ubicacion($id_elem, $lat, $long);
             $file_name = str_replace(".txt", "", $file_name);
             fwrite($fd_convertido, $ubic->__toString() . ", \"" . $file_name . "\"" . ", \"" . $file_name . "_" . $id_elem . "\"" . PHP_EOL);
         }
         fclose($fd_original);
     }
     fclose($fd_convertido);