<?php include '/../config/coneccion.php'; $cant = $_POST['cant']; do { $id = generarID($cant); $resultado = query("SELECT code FROM data_control_portal.data_control where code='" . $id . "'"); } while (pg_num_rows($resultado) > 0); function generarID($length) { $str = 'ABCDEFGHJKLMNOPQRSTUWVXYZ0123456789'; for ($i = 0; $i < $length; $i++) { echo $str[mt_rand(0, 34)]; } }
} } // >>> 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); } else { // error opening the file. echo "Lo sentimos, se ha producido un error al abrir el archivo.<br><br>"; } if (strpos($original_file, "_") != 0) {