Good morning everyone! I have a problem in the part of reopening a file in TxT, the problem that in the first statement it normally opens, writes and closes. But below in the script I try to reopen the file again and it does not even open, it just writes in it and returns the following error.
Warning: fwrite () expects parameter 1 to be resource, string given in F: \ wamp64 \ www \ nfe \ functions.php on line 70 Warning: fclose () expects parameter 1 to be resource, string given in F: \ wamp64 \ www \ nfe \ functions.php on line 71
Follow the Code:
$pasta = $data[0].$data[1].$data[2]."_".$data_end[0].$data_end[1].$data_end[2];
foreach($config->empresas as $cfg){
$txt = fopen("sintegra/SINTEGRA_".$pasta.".txt", "w");
fwrite($txt,
str_pad($cfg -> reg1, 2," ", STR_PAD_RIGHT).
str_pad($cfg -> cnpj, 14," ", STR_PAD_RIGHT).
str_pad($cfg -> ie, 14," ", STR_PAD_RIGHT).
str_pad($cfg -> rsocial, 35," ", STR_PAD_RIGHT).
str_pad($cfg -> municipio, 30," ", STR_PAD_RIGHT).
str_pad($cfg -> uf, 2," ", STR_PAD_RIGHT).
str_pad($cfg -> fone, 10," ", STR_PAD_RIGHT).
str_pad($data[2].$data[1].$data[0], 8, " ", STR_PAD_RIGHT).
str_pad($data_end[2].$data_end[1].$data_end[0], 8, " ", STR_PAD_RIGHT).
str_pad($cfg -> lreg, 3," ", STR_PAD_RIGHT).
"\r\n".
str_pad($cfg -> reg2, 2," ", STR_PAD_RIGHT).
str_pad($cfg -> endereco, 34," ", STR_PAD_RIGHT).
str_pad($cfg -> numero, 5,"0", STR_PAD_LEFT).
str_pad($cfg -> comp, 22," ", STR_PAD_RIGHT).
str_pad($cfg -> bairro, 15," ", STR_PAD_RIGHT).
str_pad($cfg -> cep, 8," ", STR_PAD_RIGHT).
str_pad($cfg -> responsavel, 28," ", STR_PAD_RIGHT).
str_pad($cfg -> fone, 12,"0", STR_PAD_LEFT)
);
fclose($txt);
}
//APENAS TESTE//
$g_txt = "sintegra/SINTEGRA_".$pasta.".txt";
fopen($g_txt, "a+");
fwrite($g_txt, "aqui ficara o conteudo!");
fclose($g_txt);