-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.php
97 lines (69 loc) · 2.65 KB
/
index.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
use thiagoalessio\TesseractOCR\TesseractOCR;
require 'vendor/autoload.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['submit'])) {
$file_name = $_FILES['file']['name'];
$tmp_file = $_FILES['file']['tmp_name'];
if (!session_id()) {
session_start();
$unq = session_id();
}
$file_name = uniqid() . '_' . time() . '_' . str_replace(array('!', "@", '#', '$', '%', '^', '&', ' ', '*', '(', ')', ':', ';', ',', '?', '/' . '\\', '~', '`', '-'), '_', strtolower($file_name));
if (move_uploaded_file($tmp_file, 'uploads/' . $file_name)) {
try {
$fileRead = (new TesseractOCR('uploads/' . $file_name))
->setLanguage('eng')
->run();
} catch (Exception $e) {
echo $e->getMessage();
}
} else {
echo "<p class='alert alert-danger'>File failed to upload.</p>";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document Reader</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<div class="row mt-5">
<div class="col-sm-8 mx-auto">
<div class="jumbotron">
<h1 class="display-4">Read Text from Images</h1>
<p class="lead">
<?php if ($_POST) : ?>
<pre>
<?= $fileRead ?>
</pre>
<?php endif; ?>
</p>
<hr class="my-4">
</div>
</div>
</div>
<div class="row col-sm-8 mx-auto">
<div class="card mt-5">
<div class="card-body">
<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="filechoose">Choose File</label>
<input type="file" name="file" class="form-control-file" id="filechoose">
<button class="btn btn-success mt-3" type="submit" name="submit">Upload</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
</body>
</html>