1

你好,我依赖卡在这里,

好的,我已经有一个工作功能可以在我的目录中为一个指定的文件更新我的数据库,现在我需要一个 php 代码来为目录中的每个文件执行相同的操作,然后将其删除。

$fileName = "IEDCBR361502201214659.RET";

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

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

函数 linhaProcessada 是

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');        
                }
          }
    }
}

真的需要帮助

4

2 回答 2

1

PHP的opendir()应该做的伎俩。更多信息在这里: 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 );
}
于 2012-05-02T21:24:40.037 回答
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);
}
?>
于 2012-05-03T01:16:23.040 回答