0
I’m using the Cakephp framework, and I need to take the value that the user enters the form and write this value to a txt file, but it’s giving me error and I don’t know what the problem is.
HTML:
<body class="bodyAddEstoque">
<h2 class="page-header">Editar Estoques</h2>
<?= $this->Form->create($produtos) ?>
<form action="/projeto/produtos/estoque/" method="post">
    <p>
        <label class="control-label">Configurar Estoque minimo: </label>
        <input type="number" name="estoque" step="any" class="form-control addDesconto inputEstoque" id="estoque"">
    </p>
    <button type="submit" class="btn btn-primary" id="click">Editar</button>
</form>
<?= $this->Form->end() ?>
Controller:
 public function configEstoque(){
        $this->paginate = [
    'contain' => ['CategoriasProdutos', 'Fornecedores']
    ];
    $produtos = $this->paginate($this->Produtos);
    $this->set(compact('produtos'));
    //Salvando os produtos   
    if(isset($_POST['estoque'])){
        //Variável arquivo armazena o nome e extensão do arquivo.    
        $arquivo = fopen('configEstoque.txt','w');
        //Variável $fp armazena a conexão com o arquivo e o tipo de ação.
        $conexao = fopen($arquivo, "a+");
        //Escreve no arquivo aberto.
        $texto = $_POST['estoque'];
        fwrite($conexao, $texto);    
        //Fecha o arquivo.
        fclose($conexao);
        $this->Flash->success(__('O produto foi editado com sucesso.'));
        return $this->redirect(['action' => 'index']);
    }
} 
But it is returning me these errors: fopen() expects Parameter 1 to be a Valid path, Resource Given Warning (2): fwrite() expects Parameter 1 to be Resource, Boolean Given Warning (2): fclose() expects Parameter 1 to be Resource, Boolean Given
Why do you do
fopen($arquivo)if$arquivois already a resource defined byfopen('configEstoque.txt')?– Woss
Ah had not touched me, I tidied up this detail, no more errors appear, however the txt file remains blank.
– LMT