-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
132 lines (111 loc) · 3.54 KB
/
upload.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
require("init.php");
/* Processing form submission */
if (isset($_FILES['image']['tmp_name'])){
$filename = uniqid("img-").".";
$urlsUploaded = array();
$bwImage = imagecreatefrompng($_FILES['image']['tmp_name']);
imagefilter($bwImage, IMG_FILTER_GRAYSCALE);
imagepng($bwImage, "/var/www/html/tmp_img/".$filename."png");
$filesToUpload = array(
0 => array(
"Bucket" => describeS3Bucket("color"),
"Key" => $filename.pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION),
"SourceFile" => $_FILES['image']['tmp_name'],
"ACL" => "public-read"
),
1 => array(
"Bucket" => describeS3Bucket("grayscale"),
"Key" => $filename."png",
"SourceFile" => "/var/www/html/tmp_img/".$filename."png",
"ACL" => "public-read"
)
);
foreach ($filesToUpload as $upload) {
$result = $s3Client->putObject($upload);
array_push($urlsUploaded, $upload["Key"]);
}
imagedestroy($bwImage);
// mySQL query
if (getRDShost()){
$successUpload = true;
connectToRDSInstance();
$query = $rdsConnection->prepare("INSERT INTO `records` (`id`, `email`, `phone`, `s3-raw-url`, `s3-finished-url`, `status`, `receipt`) VALUES (NULL, ?, ?, ?, ?, ?, ?)");
if (!$query){
echo "Prepare failed: (".$rdsConnection->errno.") ".$rdsConnection->error;
}else{
$status = 0;
$receipt = rand(11111, 99999);
$query->bind_param("ssssii", $_POST["email"], $_POST["phone"], $urlsUploaded[0], $urlsUploaded[1], $status, $receipt);
$query->execute();
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://bootswatch.com/4/sketchy/bootstrap.min.css">
<title>Upload – MP1</title>
<style>
.container{
padding-top: 5%;
background-color: transparent;
}
body{
background-color: #f3f3f4;
}
.well{
border-radius: 4px;
background-color: white;
padding: 30px 30px 30px 30px;
}
hr{
opacity: 0.4;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-8 offset-lg-2 text-center">
<?php if (isset($successUpload)):?>
<div class="alert alert-success" style="margin-bottom: 40px;">
<h4>Hooray!</h4>
<p>Photo uploaded successfully. Feel free to add more or visit our gallery section.</p>
<p><a href="gallery.php" class="btn btn-outline-info">Gallery</a></p>
</div>
<?php endif;?>
<?php if (!getRDShost()):?>
<div class="alert alert-warning" style="margin-bottom: 40px;">
<h4>Heads up!</h4>
<p>Database for this website is still being loaded, so upload capability might be restricted. Sorry for any inconveniences and please check again later!</p>
<p><a href="upload.php" class="btn btn-outline-info">Reload this page</a></p>
</div>
<?php endif;?>
<div class="well">
<h1>Upload an image</h1><hr/>
<form action="" method="POST" enctype="multipart/form-data">
<div class="row">
<div class="col-lg-6">
<input type="email" name="email" class="input-lg form-control" placeholder="Your email address">
</div>
<div class="col-lg-6">
<input name="phone" class="input-lg form-control" placeholder="Your phone">
</div>
</div>
<div class="row">
<div class="text-center col-lg-12" style="margin-top: 25px;">
<label for="image" style="margin-right: 10px">Choose file to upload</label>
<input type="file" id="image" name="image">
</div>
</div>
<hr/>
<button class="btn btn-success btn-lg">Let's do it!</button>
</form>
</div>
</div>
</div>
</div>
</body>
</html>