-
Notifications
You must be signed in to change notification settings - Fork 0
/
setCompanyInfo.php
59 lines (50 loc) · 1.5 KB
/
setCompanyInfo.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
// definition of variables
$name = '';
$address = '';
$email = '';
$phone = '';
$website = '';
$logo = '';
$dirForUpload = 'img/uploads/';
// validation function
function validateInput($data)
{
$data = trim($data);
$data = stripcslashes($data);
$data = htmlspecialchars($data);
return $data;
}//validateInput()
// obtain the data from POST
if($_POST)
{
$name = validateInput($_POST['company_name']);
$address = validateInput($_POST['company_add']);
$email = validateInput($_POST['company_email']);
$phone = validateInput($_POST['company_phone']);
$website = validateInput($_POST['company_website']);
// handling the image
$targetFile = $dirForUpload . basename($_FILES['logo']['name']);
$imageFileType = pathinfo($targetFile,PATHINFO_EXTENSION);
$check = getimagesize($_FILES['logo']['tmp_name']);
if (!move_uploaded_file($_FILES['logo']['tmp_name'], $targetFile)) {
throw new Exception('Error while uploading image',1);
}
} else {
throw new Exception("Error Processing Request", 1);
}
$company = array(
'name' => $name,
'address' => $address,
'email' => $email,
'phone' => $phone,
'website' => $website,
'logo' => $targetFile
);
//var_dump($company); die();
// saving the data into a file
file_put_contents('data.json',json_encode($company));
// redirecting to index
header('Location: ' . $_SERVER['SERVER_NAME']);
// to decode have to use
// json_decode(file_get_contents('data.json'),true);