-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdbr.php
59 lines (51 loc) · 1.6 KB
/
dbr.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
<?php
// create absolute file path
function file_build_path(...$segments) {
return join(DIRECTORY_SEPARATOR, $segments);
}
$file = basename($_FILES["readBarcode"]["name"]);
echo "<p>$file</p>";
if ($file != NULL && $file != "") {
// get current working directory
$root = getcwd();
// tmp dir for receiving uploaded barcode images
$tmpDir = "uploads/";
if (!file_exists($tmpDir)) {
mkdir($tmpDir);
}
$target_file = $tmpDir . basename($_FILES["readBarcode"]["name"]);
$isSuccessful = true;
$fileType = pathinfo($target_file,PATHINFO_EXTENSION);
if (!$isSuccessful) {
echo "Fail to read barcode";
} else {
if (move_uploaded_file($_FILES["readBarcode"]["tmp_name"], $target_file)) {
// dynamsoft barcode reader
$path = file_build_path($root, $target_file);
/*
* Description:
* array DecodeBarcodeFile( string $filename , bool $isNativeOutput [, bool $isLogOn ] )
*
* Return Values:
* If barcode detected, $array[0] is an array.
*/
$resultArray = DecodeBarcodeFile($path, false);
if (is_array($resultArray[0])) {
$resultCount = count($resultArray);
echo "Total count: $resultCount\n";
for($i = 0; $i < $resultCount ; $i++) {
$result = $resultArray[$i];
echo "<p>Barcode format: $result[0], value: $result[1]</p>";
}
}
else {
echo "<p>$resultArray[0]</p>";
}
// delete the uploaded barcode image
unlink($path);
} else {
echo "Fail to read barcode.";
}
}
}
?>