Bom dia Pessoal! Estou com um problema na parte de reabrir um arquivo em TxT, o problema que na primeira instrução o mesmo abre normalmente, escreve e fecha. Porém mais abaixo no script tento reabrir o arquivo novamente e mesmo não abre, tao pouco escreve nele e retorna o seguinte erro.
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
Segue o Codigo:
$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);