-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
executable file
·161 lines (134 loc) · 3.95 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
//ini_set('display_errors',1);
//error_reporting(E_ALL|E_STRICT);
$dbhost = 'localhost';
$dbuser = 'cakephp';
$dbpass = 'nj2kjn8s9d';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'layercakedb';
mysql_select_db($dbname);
$err = NULL;
$title = mysql_real_escape_string($_POST['title']);
$author = mysql_real_escape_string($_POST['author']);
$istyle = mysql_real_escape_string($_POST['istyle']);
$controlled = mysql_real_escape_string($_POST['controlled']);
$license = mysql_real_escape_string($_POST['license']);
$editpass = md5($_POST['editpass']);
if ($_POST['robots'] == "Enabled"){
$robots = 1;
} else {
$robots = 0;
}
$numLayers = 0;
foreach ($_FILES as $iname => $ifile) {
if ($ifile['error']==UPLOAD_ERR_OK){
$name = $ifile['tmp_name'];
$imdesc = explode(' ',exec("identify $name"));
if ($imdesc[1]=='PNG'){
$size = explode('x',$imdesc[2]);
$width = (int)$size[0];
$height = (int)$size[1];
if ($width <= 1200 || $height <= 1200){
if ($iname=='bg'){
$sizebg = $size;
} else {
if ($size==$sizebg){
$numLayers++;
} else {
$err = "Layer $iname did not have the same dimensions as the background.<br>Background: $sizebg<br>Layer $iname: $size";
break;
}
}
} else {
$err = "Images too large. Neither width or height may exceed 1200";
break;
}
} else {
$err = "Layer $iname was not a PNG.";
break;
}
}
}
if ($numLayers < 1){
$err = "You must submit at least 1 layer other than the background.";
}
if ($err == NULL){
$insert_query = "INSERT INTO cakes (title,numLayers,width,height,author,published,hearts,istyle,controlled,robots,license,editpass) VALUES ('$title',$numLayers,$width,$height,'$author',NOW(),0,$istyle,$controlled,$robots,'$license','$editpass') ;";
mysql_query($insert_query);
$result = mysql_query("SELECT LAST_INSERT_ID();");
$cake_id = mysql_fetch_array($result);
$cake_id = $cake_id[0];
$uploaddir = '/var/www/LayerCake/images/' . $cake_id;
mkdir($uploaddir,0775);
chmod($uploaddir,0775);
foreach ($_FILES as $iname => $ifile) {
if ($ifile['error']==UPLOAD_ERR_OK){
$final_path = $uploaddir . '/' . $iname . '.png';
move_uploaded_file($ifile['tmp_name'], $final_path);
chmod($final_path,0664);
}
}
// Image Work. Takes around 2 seconds on an unloaded system for a typical layercake
exec("cp $uploaddir/bg.png $uploaddir/thumb_bg.png");
exec("mogrify -resize 100x100 $uploaddir/thumb_bg.png");
chmod("$uploaddir/thumb_bg.png",0664);
for ( $ln=1; $ln<=$numLayers; $ln+=1) {
exec("cp $uploaddir/$ln.png $uploaddir/thumb_$ln.png");
exec("mogrify -resize 100x100 $uploaddir/thumb_$ln.png");
chmod("$uploaddir/thumb_$ln.png",0664);
}
exec("composite $uploaddir/thumb_1.png $uploaddir/thumb_bg.png $uploaddir/thumb.png");
for ( $ln=2; $ln<=$numLayers; $ln+=1) {
exec("composite $uploaddir/thumb_$ln.png $uploaddir/thumb.png $uploaddir/thumb.png");
}
chmod("$uploaddir/thumb.png",0664);
}
mysql_close($conn);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Layer Cake</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<style type="text/css">
body{
font-family: sans-serif;
}
.maincontain{
margin-left: 40px;
margin-right: 40px;
margin-top: 60px;
border-radius: 10px;
-moz-border-radius: 10px;
background-color: #CCCCCC;
padding: 10px;
padding-left: 22px;
}
.logo{
float:left;
border: none;
}
</style>
</head>
<body>
<div>
<a href="http://uncc.ath.cx/LayerCake/"><img class="logo" src="header.png" alt="Layer Cake (beta)"/></a>
</div>
<div> </div>
<div class="maincontain">
<p>
<?
if ($err==null){
?>
Success!<br><br>
<a href="view.php?id=<? echo $cake_id; ?>"><h3>View your LayerCake</h3></a>
<?
} else {
echo $err;
}
?>
<br><br>
</p>
</div>
</body
</html>