Colleagues.
I have the following code where I get a csv file through upload and store it in a txt file, from which you have to have the formation of the positions according to the database of a program. For this I am using the code below:
$diretorio = 'arquivos/';
$arquivo = $diretorio . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $arquivo)){
$abrirArquivo = fopen($arquivo, "r");
while(!feof($abrirArquivo)) {
$ler = fgets($abrirArquivo,460);
$campo1 = substr($ler, 0, 8);
$campo2 = substr($ler, 9,10);
$campo3 = substr($ler, 20, 10);
$campo4 = substr($ler, 31, 22);
$campo5 = substr($ler, 40, 10);
$leituraFinal = "
$campo1 $campo2 $campo3 $campo4 $campo5<br>";
//$trocar = str_replace("<br>","",$leituraFinal);
$trocar = preg_replace("<br>",null,$leituraFinal);
file_put_contents($diretorio . "JAN_2012.txt",$leituraFinal,FILE_APPEND);
file_get_contents($diretorio . "JAN_2012.txt");
}
}
}
Legal. It works, at least in parts, because in the txt file it appears at the end of the line < br >.