forked from FamilySearch/gedcomx-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
48 lines (44 loc) · 1.58 KB
/
upload.php
File metadata and controls
48 lines (44 loc) · 1.58 KB
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
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('upload_max_filesize', '10M');
ini_set('post_max_size', '10M');
require 'vendor/autoload.php';
use thiagoalessio\TesseractOCR\TesseractOCR;
if (isset($_POST['submit'])) {
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["image"]["name"]);
// Kontrollera om filen har laddats upp korrekt
if ($_FILES["image"]["error"] == UPLOAD_ERR_OK) {
// Flytta den uppladdade bilden till uploads-mappen
if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) {
echo "Bilden " . basename($_FILES["image"]["name"]) . " har laddats upp.";
// Kör OCR-skriptet på den uppladdade bilden
$ocr = new TesseractOCR($target_file);
$text = $ocr->run();
echo '<h2>Upptäckt Text:</h2>';
echo '<pre>' . $text . '</pre>';
} else {
echo "Tyvärr, det uppstod ett fel vid flyttningen av den uppladdade filen.";
}
} else {
echo "Tyvärr, det uppstod ett fel vid uppladdning av din bild. Felkod: " . $_FILES["image"]["error"];
}
} else {
echo '
<html lang="sv">
<head>
<meta charset="UTF-8">
<title>OCR Bilduppladdning</title>
</head>
<body>
<h1>Ladda upp en bild för OCR</h1>
<form action="upload.php" method="post" enctype="multipart/form-data">
Välj bild:
<input type="file" name="image" id="image">
<input type="submit" value="Ladda upp bild" name="submit">
</form>
</body>
</html>';
}
?>