variabile non riconosciuta

AndreaCerre

Utente Attivo
7 Giu 2020
37
0
6
Ciao a tutti, il codice seguente in base vari parametri crea dei file txt, dovrei aggiungere il campo $fattura (che recupero dal case 015) al file 010
ma quando arriva qui fwrite($handle010,$fattura."\r\n"); mi da questo errore:

Notice: Undefined variable: fattura in C:\Apache24\htdocs\garanzie_project_bootstrap\importafilebirdfn_add.php on line 286

ora nel file 010 la varaibile che voglio aggiungere mi viene aggiunta comunque, anche se viusalizzo questo messaggio di errore,
ma sfalzato di un riga come vedete nello screenshot

1598949266723.png


Potete aiutarmi?

Codice:
<?php

$userfile_name = $_FILES['birdfn']['name'];

$size = $_FILES['birdfn']['size'];

$idfileedr = substr($userfile_name,26,4);

$qidedrLAST = $mysqli -> query("SELECT MAX(IDEDR) AS MAXIDEDR FROM tbdfn_filebirdfn;");
$rLAST = mysqli_fetch_array($qidedrLAST);
$idLAST = $rLAST['MAXIDEDR'];

if ($idLAST == 0) {

    $idLAST = ID_LAST_BIRDFN;
    
}

echo "ultimo file caricato: ".$idLAST;
echo "\n<hr>\n\n";

$qidedrCAR = $mysqli -> query("SELECT DTACARFILE FROM tbdfn_filebirdfn WHERE IDEDR=" .$idfileedr. ";");
$rCAR = mysqli_fetch_array($qidedrCAR);
$dtaCAR = $rCAR['DTACARFILE'];

if (($qfileinseriti = $mysqli -> query("SELECT NOMFILE FROM tbdfn_filebirdfn WHERE NOMFILE = '$userfile_name'")) !== false)
if (is_object($qfileinseriti)) {
    $rfileins = mysqli_fetch_assoc($qfileinseriti);
    
    $rowcount = mysqli_num_rows($qfileinseriti);
    
}

if ($rowcount == 1)
                echo "Il file BIRDFN nr. ".$userfile_name."<br>&egrave; gi&agrave stato caricato il " .$dtaCAR. ".";
                
            elseif ( ($idfileedr - $idLAST) > 1 )
                echo "Il file BIRDFN nr. ".$userfile_name."<br>non ha l'ID progressivo richiesto.";
                
            else
                
            {
                
$uploadDir = "C:/Apache24/htdocs/garanzie_project_bootstrap/fileinputprova/";
$uploadDir2 = "C:/Apache24/htdocs/garanzie_project_bootstrap/fileoutputprova/";

foreach ($_FILES as $file) {
    if (UPLOAD_ERR_OK === $file['error']) {
        $fileName = basename($file['name']);
        move_uploaded_file($file['tmp_name'], $uploadDir.DIRECTORY_SEPARATOR.$fileName);   
    }
}

$rowsfile = count(file($uploadDir.$userfile_name));
echo "n. righe file: ".$rowsfile;
echo "\n<hr>\n\n";

$mysqli -> query ("INSERT INTO tbdfn_filebirdfn (NOMFILE,IDEDR,DIMFILE) VALUES ('".$userfile_name."','".$idfileedr."','".$size."');");

$fp = fopen($uploadDir . $userfile_name,'r+');

    //definisco le variabili per i file temporanei
    $name000 = $uploadDir2."birdfn000.txt";   
    $handle000 = fopen($name000,"w+");
    $dim000 = array(9,6,6,1,2,3,3,50,10,8,8,6);
    
    $name999 = $uploadDir2."birdfn999.txt";
    $handle999 = fopen($name999,"w+");
    $dim999 = array(9,6,6,1,2,3,6);
    
    $name005 = $uploadDir2."birdfn005.txt";
    $handle005 = fopen($name005,"w+");
    $dim005 = array(9,6,6,1,2,3,2,1,1,1,8,1);

    $name010 = $uploadDir2."birdfn010.txt";
    $handle010 = fopen($name010,"w+");
    $dim010 = array(9,6,6,1,2,3,17,10,7,19,1,8,6,8,6,12,8,8,3,9,15,15,2,2,12,12,12,8,6,1,1,1,1,50,12,1);
    
    $name011 = $uploadDir2."birdfn011.txt";
    $handle011 = fopen($name011,"w+");
    $dim011 = array(24,3,5,268);
    
    $name112 = $uploadDir2."birdfn112.txt";
    $handle112 = fopen($name112,"w+");
    $dim112 = array(9,6,6,1,2,3,1,1,108,2,10,10,60,25,10,8,1,4,1,2,8,2,2,2,2,2,4,4,2,2);
    
    $name113 = $uploadDir2."birdfn113.txt";
    $handle113 = fopen($name113,"w+");
    $dim113 = array(9,6,6,1,2,3,50,2,9,3,3,5,35,35,35,35,4,5,9,1);
    
    $name114 = $uploadDir2."birdfn114.txt";
    $handle114 = fopen($name114,"w+");
    $dim114 = array(9,6,6,1,2,3,100,5,9,35,6,15,6,15,6,15,6,10,1,20,20);
    
    $name015 = $uploadDir2."birdfn015.txt";
    $handle015 = fopen($name015,"w+");
    $dim015 = array(9,6,6,1,2,3,1,8,1,6,3,1,15,1,15,1,15,10,20,6,20,30,6);
                
    $name016 = $uploadDir2."birdfn016.txt";
    $handle016 = fopen($name016,"w+");
    $dim016 = array(9,6,6,1,2,3,1,5,1,15,1,15,1,15);
                    
    $name017 = $uploadDir2."birdfn017.txt";
    $handle017 = fopen($name017,"w+");
    $dim017 = array(9,6,6,1,2,3,3,20,50,1,15,1,15,1,15,1,5,6,6,6,6,15,15);
    
    $name020 = $uploadDir2."birdfn020.txt";
    $handle020 = fopen($name020,"w+");
    $dim020 = array(9,6,6,1,2,3,3,4,3,2,2,3,3,1,8,6,6,4,4,10,8,1,1,15,1,15,1,15,1,15,1,3,1,11,11,1,2,4,4,4,4);
    
    $name023 = $uploadDir2."birdfn023.txt";
    $handle023 = fopen($name023,"w+");
    $dim023 = array(9,6,6,1,2,3,3,200);

    $name025 = $uploadDir2."birdfn025.txt";
    $handle025 = fopen($name025,"w+");
    $dim025 = array(9,6,6,1,2,3,2,120);
    
    $name030 = $uploadDir2."birdfn030.txt";
    $handle030 = fopen($name030,"w+");
    $dim030 = array(9,6,6,1,2,3,80);
    
    $name040 = $uploadDir2."birdfn040.txt";
    $handle040 = fopen($name040,"w+");
    $dim040 = array(9,6,6,1,2,3,100);
    
    $name050 = $uploadDir2."birdfn050.txt";
    $handle050 = fopen($name050,"w+");
    $dim050 = array(9,6,6,1,2,3,8,35,1,1,3,13,1,5,5,1,15,1,15,4,4,4,4,4,4,4,4,4,4,1,1,1);
    
    $name060 = $uploadDir2."birdfn060.txt";
    $handle060 = fopen($name060,"w+");
    $dim060 = array(9,6,6,1,2,3,10,17,2,1,5,1,1,1,1,1,1,15,5,5,5,1,15,1,15,1);           
                    
    $name070 = $uploadDir2."birdfn070.txt";
    $handle070 = fopen($name070,"w+");
    $dim070 = array(9,6,6,1,2,3,6,35,35,1,15,5,5,1,15,1,15,2,10);
    
    $name080 = $uploadDir2."birdfn080.txt";
    $handle080 = fopen($name080,"w+");
    $dim080 = array(9,6,6,1,2,3,8,35,3,4,4,4,4,4,4,4,4,4,4);
    
    $name090 = $uploadDir2."birdfn090.txt";
    $handle090 = fopen($name090,"w+");
    $dim090 = array(9,6,6,1,2,3,10,2,17,5,1);
    
    $index = 0;
    $lines = file($uploadDir. $userfile_name);
    
    $last = sizeof($lines) -1 ;
    //echo "\n<hr>\n\n";*/
    
    foreach ($lines as $line_num => $line) {
    
    $line = str_replace(array("\t","\a","\b","\n","\v","\f","\r","\e","\s","\d"),array(" "," "," "," "," "," "," "," "," "),$line);

    $line = preg_replace('/(?>[\x00-\x1F]|\xC2[\x80-\x9F]|\xE2[\x80-\x8F]{2}|\xE2\x80[\xA4-\xA8]|\xE2\x81[\x9F-\xAF])/', '', $line);

    $line = str_replace(array("Ã","Å","Ä","À","Á","Â","Ç","Č","É","È","Ê","Ë","Ĕ","Ğ","Ģ","Ï","Î","Í","Ì","Ñ","Ö","Ô","Ō","Ò","Ó","Ø","Ŝ","Ş","Ü","Ū","Û","Ù","Ú","Ÿ"),
                        array("A","A","A","A","A","A","C","C","E","E","E","E","E","G","G","I","I","I","I","N","O","O","O","O","O","O","S","S","U","U","U","U","U","Y"), $line);
    
    
    $line = str_replace(array("å","å","ä","à","á","â","ç","č","é","è","ê","ë","ĕ","ğ","ģ","ï","î","í","ì","ñ","ö","ô","ō","ò","ó","ø","ŝ","ş","ü","ū","û","ù","ú","ÿ"),
                        array("A","A","A","A","A","A","C","C","E","E","E","E","E","G","G","I","I","I","I","N","O","O","O","O","O","O","S","S","U","U","U","U","U","Y"), $line);
    

    /*echo $line;
    echo "\n<hr>\n\n";
    
    echo strlen($line);
    echo "\n<hr>\n\n";*/

    if ($line_num != $last){
    if (strlen($line) <> 302){
        
        echo "ATTENZIONE IL FILE BIRDFN nr. ".$userfile_name." NON E' FORMATTATO CORRETTAMENTE ALLA RIGA ".$line_num." MODIFICARE IL FILE E RICARICARLO SU CARTELLA SERVER RENAULT";
        echo "\n<hr>\n\n";
        //echo "MODIFICARE IL FILE E RICARICARLO";
        //echo "\n<hr>\n\n";
    }
    }
    
    $sottstrin = substr($line,24,3);
    
    switch ($sottstrin) {

  
    
    case "015" :
    //Record 015 - Invoice
    fwrite($handle015,$idfileedr.";");
    for ($i = 0; $i < count($dim015); $i++) {
                    $field = str_replace(array(chr(192),chr(176),chr(204)),array("A"," "," "),str_pad (substr($line,$index,$dim015[$i]),$dim015[$i]," ",STR_PAD_RIGHT));
                    $field = $field.";";
                    
                    
                    fwrite($handle015,$field);
                    $index += $dim015[$i];
                }
                $fattura = substr($line, 9,6);
                fwrite($handle015,$fattura."\r\n");
                $index = 0;
    
    break;   
    
    case "010" :
    //Record 010 – Dealer Header
    fwrite($handle010,$idfileedr.";");
    for ($i = 0; $i < count($dim010); $i++) {
                    $field = str_replace(";","",str_pad (substr($line,$index,$dim010[$i]),$dim010[$i]," ",STR_PAD_RIGHT));
                    $field = $field.";";
                    fwrite($handle010,$field);
                    $index += $dim010[$i];
                }
                fwrite($handle010,$fattura."\r\n");
                $index = 0;
    break;