-
Notifications
You must be signed in to change notification settings - Fork 3
/
upload.php
147 lines (140 loc) · 6.4 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if (isset($_POST["submit"]) && $_POST["submit"] != null) {
$check = @getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if ($check !== false) {
//echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image (or there was no file uploaded).";
echo '<br><center>
<form action="main.php" method="POST">
<input type="hidden" name="idtoken" value="' . $_POST['idtoken'] . '" />
<input type="submit" value="Try Another Image" required />
</form></center>';
$uploadOk = 0;
die();
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 5000000) {
echo "Sorry, your file must be less than 5 MB.";
$uploadOk = 0;
}
// Allow certain file formats
if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo " Your file was not uploaded.";
echo '<br><center>
<form action="main.php" method="POST">
<input type="hidden" name="idtoken" value="' . $_POST['idtoken'] . '" />
<input type="submit" value="Try Another Image" required />
</form></center>';
die();
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file '" . basename($_FILES["fileToUpload"]["name"]) . "' has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
list($width_original, $height_original) = getimagesize($target_file);
checkImage();
// Prints out the correct size of the image
function checkImage() {
global $width_original, $height_original;
if ($width_original > 1024 && $height_original > 768) {
$width = 1024;
$height = 768;
printImage($width, $height);
} else if ($width_original > 1024 && $height_original <= 768) {
$width = 1024;
printImage($width, $height_original);
} else if ($width_original <= 1024 && $height_original > 768) {
$height = 768;
printImage($width_original, $height);
} else {
printImage($width_original, $height_original);
}
}
// Prints out the image
function printImage($width, $height) {
global $width_original, $height_original, $target_file;
echo "<center><font color=\"red\">Note: Some images are too large, so they get
truncated. Click on images to show full size, double click to restore to
original size!</font> <br><br><img src= \"$target_file\" alt=\"image\"
width=\"$width\" height=\"$height\" style=\"cursor:pointer;cursor:hand\"
onclick=\"this.src='$target_file'; this.height='$height_original';
this.width='$width_original'\" ondblclick=\"this.src='$target_file';
this.height='$height';this.width='$width'\" /></center>";
}
?>
<br>
<br>
<center><div style="display: inline-block">
<form action="image_filter.php" method="POST">
<input type="submit" name "grayscale" value="Grayscale" />
<input type="hidden" name="target_file" value="<?php echo $target_file ?>" />
<input type="hidden" name="image_file_type" value="<?php echo $imageFileType ?>" />
<input type="hidden" name="filename" value="<?php echo basename($_FILES["fileToUpload"]["name"]) ?>" />
<input type="hidden" name="grayscale" value="gray" />
</form></div>
<div style="display: inline-block">
<form action="image_filter.php" method="POST">
<input name "edgedetect" type="submit" id="submit" value="EdgeDetect" />
<input type="hidden" name="target_file" value="<?php echo $target_file ?>" />
<input type="hidden" name="image_file_type" value="<?php echo $imageFileType ?>" />
<input type="hidden" name="filename" value="<?php echo basename($_FILES["fileToUpload"]["name"]) ?>" />
<input type="hidden" name="edgedetect" value="edge" />
</form></div>
<div style="display: inline-block">
<form action="image_filter.php" method="POST">
<input name "emboss" type="submit" id="submit" value="EMBOSS" />
<input type="hidden" name="target_file" value="<?php echo $target_file ?>" />
<input type="hidden" name="image_file_type" value="<?php echo $imageFileType ?>" />
<input type="hidden" name="filename" value="<?php echo basename($_FILES["fileToUpload"]["name"]) ?>" />
<input type="hidden" name="emboss" value="emboss" />
</form></div>
<div style="display: inline-block">
<form action="image_filter.php" method="POST">
<input name "mean_removal" type="submit" id="submit" value="Mean Removal" />
<input type="hidden" name="target_file" value="<?php echo $target_file ?>" />
<input type="hidden" name="image_file_type" value="<?php echo $imageFileType ?>" />
<input type="hidden" name="filename" value="<?php echo basename($_FILES["fileToUpload"]["name"]) ?>" />
<input type="hidden" name="mean_removal" value="mean" />
</form></div>
<div style="display: inline-block">
<form action="image_filter.php" method="POST">
<input name "negate" type="submit" id="submit" value="Negate" />
<input type="hidden" name="target_file" value="<?php echo $target_file ?>" />
<input type="hidden" name="image_file_type" value="<?php echo $imageFileType ?>" />
<input type="hidden" name="filename" value="<?php echo basename($_FILES["fileToUpload"]["name"]) ?>" />
<input type="hidden" name="negate" value="negate" />
</form></div>
<div style="display: inline-block">
<form action="image_filter.php" method="POST">
<input name "sepia" type="submit" id="submit" value="Sepia" />
<input type="hidden" name="target_file" value="<?php echo $target_file ?>" />
<input type="hidden" name="image_file_type" value="<?php echo $imageFileType ?>" />
<input type="hidden" name="filename" value="<?php echo basename($_FILES["fileToUpload"]["name"]) ?>" />
<input type="hidden" name="sepia" value="sepia" />
</form></div>
<br><form action="main.php" method="POST">
<input type="submit" name="try_another_image" value="Try Another Image" />
<input type="hidden" name="target_file" value="<?php echo $target_file ?>" />
<input type="hidden" name="idtoken" value="<?php echo $_POST['idtoken'] ?>" />
</form></center>