1 | #!/usr/local/bin/php -q |
---|
2 | <?php |
---|
3 | /** |
---|
4 | * file_importer.cli.php |
---|
5 | * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information |
---|
6 | */ |
---|
7 | |
---|
8 | // This file is only an example. |
---|
9 | |
---|
10 | |
---|
11 | // require realpath(dirname(__FILE__) . '/..') . '/config/cli_config.inc.php'; |
---|
12 | // |
---|
13 | // $app =& App::getInstance(); |
---|
14 | // $db =& DB::getInstance(); |
---|
15 | // |
---|
16 | // |
---|
17 | // // Test arguments. |
---|
18 | // if ($_SERVER['argc'] == 2 && is_dir($_SERVER['argv'][1])) { |
---|
19 | // $file_dir = preg_replace('/\/$/', '', $_SERVER['argv'][1]); |
---|
20 | // } else { |
---|
21 | // die("You must specify the directory of files to import as the only argument.\n"); |
---|
22 | // } |
---|
23 | // |
---|
24 | // // Get array of all files. |
---|
25 | // $files = getFilesRecursive($file_dir, 1); |
---|
26 | // |
---|
27 | // // Loop through files. |
---|
28 | // // dump($files); |
---|
29 | // $file_count = 0; |
---|
30 | // if (is_array($files) && !empty($files)) { |
---|
31 | // foreach ($files as $file) { |
---|
32 | // if ($fp = fopen($file, 'r')) { |
---|
33 | // echo ++$file_count . "\n"; |
---|
34 | // $file_text = join('', file($file)); |
---|
35 | // fclose($fp); |
---|
36 | // |
---|
37 | // // Do something with file contents. |
---|
38 | // preg_match('/BALANCE:\s*\$([\.\d]+)/', $file_text, $amt); |
---|
39 | // $file_date = date('Y-m-d', strtotime(preg_replace('|[^_]*_|', '', basename($file)))); |
---|
40 | // // $db->query(" |
---|
41 | // // INSERT INTO invoice_tbl ( |
---|
42 | // // client_id, |
---|
43 | // // invoice_type, |
---|
44 | // // invoice_date, |
---|
45 | // // invoice_amount, |
---|
46 | // // invoice_status, |
---|
47 | // // payment_type, |
---|
48 | // // invoice_text, |
---|
49 | // // email_sent_datetime, |
---|
50 | // // added_datetime |
---|
51 | // // ) VALUES ( |
---|
52 | // // '" . $db->escapeString(0) . "', |
---|
53 | // // '" . $db->escapeString('hosting') . "', |
---|
54 | // // '" . $db->escapeString($file_date) . "', |
---|
55 | // // '" . $db->escapeString($amt[1]) . "', |
---|
56 | // // '" . $db->escapeString('Paid') . "', |
---|
57 | // // '" . $db->escapeString('') . "', |
---|
58 | // // '" . $db->escapeString($file_text) . "', |
---|
59 | // // '" . $db->escapeString($file_date) . "', |
---|
60 | // // NOW() |
---|
61 | // // ) |
---|
62 | // // "); |
---|
63 | // |
---|
64 | // } else { |
---|
65 | // $app->logMsg('Could not open file: ' . $file, LOG_INFO, __FILE__, __LINE__); |
---|
66 | // } |
---|
67 | // } |
---|
68 | // $app->logMsg('Proccessing complete: ' . $file_count . ' files total.', LOG_INFO, __FILE__, __LINE__); |
---|
69 | // } else { |
---|
70 | // $app->logMsg('No files available in that directory.', LOG_INFO, __FILE__, __LINE__); |
---|
71 | // } |
---|
72 | // |
---|
73 | // |
---|
74 | // |
---|
75 | // |
---|
76 | // /** |
---|
77 | // * Find all files in directories recursivly with a specified file extension. |
---|
78 | // * |
---|
79 | // * @param string $dir the full path to the directory to scan |
---|
80 | // * @param array $valid_extensions valid extensions |
---|
81 | // * @param int $recurs_lev how many levels deep to scan. Set this |
---|
82 | // * to a low number to prevent infinite loops |
---|
83 | // * |
---|
84 | // * @return array multi-dimentional array of found files on success |
---|
85 | // */ |
---|
86 | // function getFilesRecursive($dir, $recurs_lev=0, $return=true) |
---|
87 | // { |
---|
88 | // static $output; |
---|
89 | // |
---|
90 | // $dir_handle = opendir($dir); |
---|
91 | // while ($dir_handle && ($file = readdir($dir_handle)) !== false) { |
---|
92 | // if (!preg_match('/^\./', $file)) { |
---|
93 | // if (is_dir($dir . '/' . $file) && $recurs_lev > 0) { |
---|
94 | // getFilesRecursive($dir . '/' . $file, $valid_extensions, $recurs_lev - 1); |
---|
95 | // } else if (!is_dir($dir . '/' . $file)) { |
---|
96 | // $output[] = $dir . '/' . $file; |
---|
97 | // } |
---|
98 | // } |
---|
99 | // } |
---|
100 | // if ($return) { |
---|
101 | // return $output; |
---|
102 | // } |
---|
103 | // } |
---|
104 | // |
---|
105 | // ?> |
---|