1

Hello i'm rely stuck here,

Ok i already have a working function to update my database for ONE specified file, in my directory, now i need a php code to do the same thing for each file on directory and then delete it.

$fileName = "IEDCBR361502201214659.RET";

$cnab240 = RetornoFactory::getRetorno($fileName, "linhaProcessada");

$retorno = new RetornoBanco($cnab240);
$retorno->processar();

the function linhaProcessada is

function linhaProcessada2($self, $numLn, $vlinha) {
if($vlinha["registro"] == $self::DETALHE ) 
    {
        if($vlinha["registro"] == $self::DETALHE && $vlinha["segmento"] == "T" ) {
            //define a variavel do nosso numero como outra usavel
            $query ="SELECT * FROM jos_cobra_boletos WHERE nosso_numero = ".$vlinha['nosso_numero']."";
            echo "Boleto de numero: ".$vlinha['nosso_numero']." Atualizado com sucesso!<hr>";
            $testResult = mysql_query($query) or die('Error, query failed');
                if(mysql_fetch_array($testResult) == NULL){
                }else{
                $query = "UPDATE jos_cobra_boletos
                  SET status_pagamento='Pago'
                  WHERE nosso_numero=".$vlinha['nosso_numero']."";
                  $result = mysql_query($query) or die('Erro T');        
                }
          }
    }
}

Really need help on this one

2
  • Does this help: stackoverflow.com/questions/2014474/… ? Commented May 2, 2012 at 21:12
  • I need to do the exact same thing you're doing. I like it when I find questions like that. +1 for fun. Commented Jan 27, 2014 at 3:08

2 Answers 2

1

PHP's opendir() ought to do the trick. More info here: http://php.net/manual/en/function.opendir.php

<?php
// Set Directory
$dir = '/abs/path/with/trailing/slash/';
if ($handle = opendir( $dir )) { // Scan directory
    while (false !== ($file = readdir($handle))) { // Loop each file

        $fileName = $dir . $file;

        // Run code on file 
        $cnab240 = RetornoFactory::getRetorno($fileName, "linhaProcessada");

        $retorno = new RetornoBanco($cnab240);
        $retorno->processar();

        // Delete file
        unlink( $fileName );
    }
    closedir( $handle );
}
Sign up to request clarification or add additional context in comments.

2 Comments

thanks but didnt work, blank page, i guess the function is not being called =/, any ideas?
Are you certain the $dir variable is set with the correct path? Can you turn on verbose error reporting, or look at your access logs, to see where the error is? At the very top, add this line: error_reporting(E_ALL); ini_set('error_reporting', E_ALL);
0
<? //PHP 5.4+
foreach(
    new \GlobIterator(
        __DIR__ . '/*.RET', //Or other directory where these files are
        \FilesystemIterator::SKIP_DOTS |
        \FilesystemIterator::CURRENT_AS_PATHNAME
    )

    as $pathname
){
    (new RetornoBanca(
        RetornoFactory::getRetorno($pathname, 'linhaProcessada')
    ))
    ->processar();

    \unlink($pathname);
}
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.