Problem to open file

1

When I search for a .txt file to import, it returns me the warnings

  

Warning: fopen (Clients.txt): failed to open stream: No such file or   directory in /var/www/html/systems/help-desk/processa/proc_letxt.php   online 9

     

Warning: fgets () expects parameter 1 to be resource, boolean given in   /var/www/html/sistemas/help-desk/processa/proc_letxt.php on line 12

     

Warning: fclose () expects parameter 1 to be resource, boolean given in   /var/www/html/systems/help-desk/processa/proc_letxt.php on line 23

follow code:

header('Content-type: text/html; charset=UTF-8');

//local do arquivo

if (isset($_FILES['arquivo'])) {

    $arquivo = fopen($_FILES['arquivo']['name'], "r");

    // le as linhas do arquivo
    while (($linha = fgets($arquivo)) == true) {

        // divide os dados com separador "|"
        $parte = explode("|", $linha);

        // execulta query bd
        /*$sql = "INSERT INTO clientes (nome, cpf_cpnj) VALUES ('" . $parte[0] . "', '" . $parte[1] . "', '" . $parte[2] . "')";
        $result = mysqli_query($con, $sql);*/

        echo "<br>"."CNPJ: " . $parte[0] . "<br>" . "IE: " . $parte[1] . "<br>" . "Nome: " . $parte[2] . "<br>" . "E-mail: " . $parte[3] . "<br>" . "Fone: " . $parte[4] . "<br>" . "CEP: " . $parte[5] . "<br>" . "Logradouro: " . $parte[6] . "<br>";
    }
    fclose($arquivo);
} else {
    echo "erro";
}
    
asked by anonymous 24.03.2017 / 14:28

1 answer

1

The file path is in the tmp_name index.

The index name returns only the original file name.

Just swap name by tmp_name in this section:

$arquivo = fopen($_FILES['arquivo']['tmp_name'], "r");

There are other pertinent points but I prefer to refrain from commenting in order to avoid dispersing attention to the main focus.

See: link

    
24.03.2017 / 18:54