array(1,10), 'CODE_SOC' => array(11,20), 'CODE_ART' => array(31,50), 'QTE' => array(81,10), ); $format = $STK; if($magistorModule->active) { require_once('connection_ftp.php'); @set_time_limit(0); // Checking for ".bal" files with a "STK" prefix that has an equivalent ".dat" file and process them... $inFolder = dirname(__FILE__) . '/IN/'; $iterator = new DirectoryIterator($inFolder); foreach ($iterator as $fileinfo) { if ($fileinfo->isFile()) { if( preg_match( '@^STK(.*)\.BAL@', $fileinfo->getFilename() ) ) { $datFile = $fileinfo->getPath() . '/' . preg_replace( '@BAL$@', 'DAT', $fileinfo->getFilename() ); if( file_exists( $datFile ) ) { $content = file_get_contents( $datFile ); $lines = preg_split( '@\n@', $content ); // ANTADIS if( !empty($lines) ) { foreach( $lines as $line ) { $data = array(); foreach($format as $field => $value) { $data[] = substr($line, ($value[0]-1), $value[1]); } if( !isset($data[2]) || (isset($data[2]) && !$data[2]) ) continue; $ids = explode('_', trim($data[2])); $id_product = (int)$ids[0]; if (isset($ids[1]) && (int) $ids[1]) $id_product_attribute = (int) $ids[1]; else $id_product_attribute = 0; } } $repo_archive = './archives/IN/STOCK/'; $repo_paths = array(date('Y'), date('m')); foreach ($repo_paths as $repo_path) { $repo_archive .= $repo_path . '/'; if (!file_exists($repo_archive)) mkdir($repo_archive); } copy($datFile, $repo_archive . preg_replace( '@BAL$@', 'DAT', $fileinfo->getFilename() )); unlink($inFolder.$fileinfo->getFilename()); unlink($datFile); } } } } }