-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
55 lines (48 loc) · 1.29 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
<?php
define("MB", 1048576);
function filterRequest($requestname)
{
return htmlspecialchars(strip_tags($_POST[$requestname]));
}
function imageUpload($imageRequest)
{
global $msgError;
$imagename = rand(1000, 10000) . $_FILES[$imageRequest]['name'];
$imagetmp = $_FILES[$imageRequest]['tmp_name'];
$imagesize = $_FILES[$imageRequest]['size'];
$allowExt = array("jpg", "png", "gif", "mp3", "pdf");
$strToArray = explode(".", $imagename);
$ext = end($strToArray);
$ext = strtolower($ext);
if (!empty($imagename) && !in_array($ext, $allowExt)) {
$msgError = "EXT";
}
if ($imagesize > 2 * MB) {
$msgError = "size";
}
if (empty($msgError)) {
move_uploaded_file($imagetmp, "../upload/" . $imagename);
return $imagename;
} else {
return "fail";
}
}
function deleteFile($dir, $imagename)
{
if (file_exists($dir . "/" . $imagename)) {
unlink($dir . "/" . $imagename);
}
}
function checkAuthenticate()
{
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
if ($_SERVER['PHP_AUTH_USER'] != "Hany" || $_SERVER['PHP_AUTH_PW'] != "Password") {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Page Not Found';
exit;
}
} else {
exit;
}
}