-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTexttoDB.php
executable file
·81 lines (69 loc) · 1.88 KB
/
TexttoDB.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
$fn=$_GET['file'];
$c=$_GET['page'];
$servername = "localhost";
$username = "root";
$password = "gopre222";
$dbname = "people";
$html="";
$dir='/var/www/html/OCR/Final/*_p_' .$c . '*.txt';
// Open a known directory, and proceed to read its contents
$x=0;
//echo $dir;
$records = array
(
array("null","null","null"),
array("null","null","null"),
array("null","null","null"),
array("null","null","null"),
array("null","null","null"),
array("null","null","null"),
array("null","null","null"),
array("null","null","null"),
array("null","null","null"),
array("null","null","null"),
array("null","null","null")
);
foreach(glob($dir) as $file)
{
$filen = basename($file); // $file is set to "index.php"
$filename = basename($path, ".txt"); // $file is set to "index"
$x++;
$filetxt = mysql_escape_string (nl2br(file_get_contents($filename )));
$pieces = explode("_", $file);
$row = intval($pieces[3]); // record
$col = intval($pieces[4]); // field
$orfn = $pieces[1]; // field
print_r($pieces);
echo ( "<BR> <BR><BR>");
if (($row <9 ) && ($col <9 ) ){
$records[$row][$col]=$filetxt;
echo("setting $row :: col $col <Br>");
}
else{
$html.= "Invalid RowCol:$row :: $col";
}
}
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$x=0;
$pn="";
foreach ($records as $value) {
$sql = "INSERT INTO people (page, alpha, address, amt, secured,pname);
VALUES ('$x', 'A', '$value[0]','$value[1]''$value[2]',$pn)";
$x++;
if ($conn->query($sql) === TRUE) {
//
} else {
$html.= "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
echo ("dfasdfsd");
$obj = (object) array('count' => $x, 'html' => "$html");
echo json_encode($obj);
?>