I have a code that reads a txt and saves it in the database, but sometimes it will receive more values, eg:
I have the following txt:
|texto|texto|texto|
|texto|texto|texto|texto|
If I use to receive the 4 fields, it gives error in having only 3, what could be done?
Here is 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')";