-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
61 lines (51 loc) · 1.61 KB
/
functions.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
<?php
function startSession() {
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
}
function redirectTo($location) {
header("Location: $location");
die();
}
function htmlEscape($str) {
return htmlspecialchars($str, ENT_QUOTES, "UTF-8");
}
function printArr($arr, $dieAfter = false) {
echo "<pre>";
print_r($arr);
echo "</pre>";
if ($dieAfter) die();
}
function sendResponse($responseMessage, $responseCode = 500, $die = true) {
http_response_code($responseCode);
header('Content-Type: application/json');
echo '{"code": '.$responseCode.', "message": "'.$responseMessage.'"}';
if ($die !== false) die();
}
function formatBytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return round($bytes, $precision) . ' ' . $units[$pow];
}
function exifToGPS($coordinate, $hemisphere) {
if (is_string($coordinate)) {
$coordinate = array_map("trim", explode(",", $coordinate));
}
for ($i = 0; $i < 3; $i++) {
$part = explode('/', $coordinate[$i]);
if (count($part) == 1) {
$coordinate[$i] = $part[0];
} else if (count($part) == 2) {
$coordinate[$i] = floatval($part[0])/floatval($part[1]);
} else {
$coordinate[$i] = 0;
}
}
list($degrees, $minutes, $seconds) = $coordinate;
$sign = ($hemisphere == 'W' || $hemisphere == 'S') ? -1 : 1;
return $sign * ($degrees + $minutes/60 + $seconds/3600);
}