2
I have a code that reads a txt and saves in the database, only sometimes it will receive more values, example:
I have the following txt:
|texto|texto|texto|
|texto|texto|texto|texto|
If I use to receive the 4 fields, it gives error in what have only 3, what could be done?
Just follow my code:
<?php
session_start();
ob_start();
include_once("conexao.php");
$arquivo_tmp = $_FILES['arquivo']['tmp_name'];
$dados = file($arquivo_tmp);
foreach($dados as $linha){
$linha = trim($linha);
$valor = explode('|', $linha);
$REG = $valor[1];
$COD = $valor[2];
$UNID = $valor[3];
$QTD = $valor[4];
$cod1 = "INSERT INTO temp (REG, COD, UNID, QTD) VALUES ('$REG','$COD_ITEM','$UNID','$QTD')";