Problem to open file

Asked

Viewed 154 times

1

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

Warning: fopen(.txt Clients): failed to open stream: No such file or directory in /var/www/html/sistemas/help-desk/processa/proc_letxt.php on line 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/sistemas/help-desk/processa/proc_letxt.php on line 23

follows 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";
}

1 answer

1

The file path is in the index tmp_name.

The index name returns only the original file name.

Just exchange name for tmp_name in that passage:

$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.

Consult: http://php.net/manual/en/reserved.variables.files.php

Browser other questions tagged

You are not signed in. Login or sign up in order to post.