3
$default_precision = 120;
14
function get_string($f, $exit = true) {
17
while ((!$t)&&(!feof($f)))
18
$t = preg_replace("/\s+$/", "", fgets($f));
20
if ((!$t)&&($exit)) do_exit();
24
function just_t1($t1) {
28
for ($i=0;$i<$size2;$i++) echo ", 0";
32
if ((isset($_FILES))&&(isset($_FILES['file1']))&&(isset($_FILES['file2']))) {
33
header("Content-type: application/binary");
34
header("Content-Disposition: attachment; filename=\"merged.csv\"");
35
header("Cache-Control: no-cache, must-revalidate");
36
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
38
if (isset($_POST['precision'])) {
39
$precision = intval($_POST['precision']);
40
if ($precision <= 0) $precision = $default_precision;
41
} else $precision = $default_precision;
42
$iprecision = $i_multiplyer * $precision;
44
$f1 = fopen($_FILES['file1']['tmp_name'], "r");
45
$f2 = fopen($_FILES['file2']['tmp_name'], "r");
46
if ((!$f1)||(!$f2)) do_exit();
48
$t1 = get_string($f1);
49
$t2 = get_string($f2);
51
$size1 = sizeof(split(",",$t1)) - 1;
52
$size2 = sizeof(split(",",$t2)) - 1;
54
$t2 = substr($t2, strpos(",", $t2) + 1);
55
echo $t1 . $t2 . "\r\n";
58
$t1 = get_string($f1);
59
$d1 = split (",", $t1, 2); $time1 = strtotime($d1[0]);
62
$t2 = get_string($f2);
63
$d2 = split (",", $t2, 2); $time2 = strtotime($d2[0]);
64
$tpre = $time2; $pre = $d2[1];
67
$cprecision = $precision;
68
while (($t1)&&(($time2-$cprecision)>$time1)) {
69
just_t1($t1); $cprecision = 0;
71
$t1 = get_string($f1, false);
74
$d1 = split (",", $t1, 2); $time1 = strtotime($d1[0]);
79
while (($f2)&&($time2 < $time1)) {
80
$tpre = $time2; $pre = $d2[1];
82
$t2 = preg_replace("/\s+$/", "", fgets($f2));
89
$d2 = split (",", $t2, 2); $time2 = strtotime($d2[0]);
92
if ($time2 > $time1) {
93
if (($tpre + $iprecision) > $time1)
94
echo $t1 . ", " . $pre . "\r\n";
95
elseif (($time2 - $precision) < $time1)
96
echo $t1 . ", " . $d2[1] . "\r\n"; /* = */
100
elseif (($t2)||(($time2 + $precision) > $time1))
101
echo $t1 . ", " . $d2[1] . "\r\n";
105
$t1 = get_string($f1);
108
$d1 = split (",", $t1, 2); $time1 = strtotime($d1[0]);
112
if ($f2) fclose($f2);
117
header("Content-Type: text/html; charset=UTF-8");
118
header("Cache-Control: no-cache, must-revalidate");
119
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
126
<form action="csvmerge.php" enctype="multipart/form-data" method="POST">
127
<tr><td>Master File (CSV): </td><td><input type="file" name="file1"/></td></tr>
128
<tr><td>Complementary File (CSV): </td><td><input type="file" name="file2"/></td></tr>
129
<tr><td>Precision (sec): </td><td><input name="precision" type="text" value="<?echo $default_precision;?>"/></td></tr>
130
<tr><td colspan="2"><input type="submit" value="Merge"/></td></tr>
132
</table></div></body>
b'\\ No newline at end of file'