-
Notifications
You must be signed in to change notification settings - Fork 3
/
createapp.php
97 lines (78 loc) · 2.94 KB
/
createapp.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
<?php
include 'admincheck.php';
$a = $_POST['name'];
// Replace colons in app name
$a = str_replace(";", "_", $a);
$a = str_replace("'", "_", $a);
$a = str_replace("`", "_", $a);
$a = str_replace("~", "_", $a);
$a = str_replace("<", "_", $a);
$d = $_POST['summary'];
$d = strip_tags($d, ALLOWEDHTML);
$l = $_POST['location'];
$l = str_replace("<", "_", $l);
/* Upload the screenshots */
$total = count($_FILES['filesToUpload']['name']);
/* String to hold the file names to insert into the database */
$fileString = "";
// Loop through each file
for($i=0; $i<$total; $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['filesToUpload']['tmp_name'][$i];
//Make sure we have a filepath
if ($tmpFilePath != ""){
//Setup our new file path
$fileName = rand(100, 10000) . $_FILES['filesToUpload']['name'][$i];
$fileName = str_replace(" ", "_", $fileName);
$fileName = str_replace(",", "_", $fileName);
$fileName = str_replace("`", "_", $fileName);
$fileName = str_replace(":", "_", $fileName);
$fileName = str_replace(";", "_", $fileName);
$fileName = str_replace("'", "_", $fileName);
$fileName = str_replace('"', "_", $fileName);
$fileName = str_replace("+", "_", $fileName);
$fileName = str_replace("=", "_", $fileName);
$newFilePath = "img/" . $fileName;
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $newFilePath)) {
//Now the files are uploaded, so insert them into the database
if($i > 0) {
$fileString .= ",";
}
$fileString .= $fileName;
}
}
}
/* Now prepare the MySQL insert */
/* Include the config file */
require_once "config.php";
/* and the database file */
require_once "db.php";
// Create connection
$conn = new mysqli($host, $user, $pass, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$original = mysqli_real_escape_string($conn, $_POST['original']);
$changes = mysqli_real_escape_string($conn, $_POST['changes']);
$version = mysqli_real_escape_string($conn, $_POST['version']);
$a = mysqli_real_escape_string($conn, $a);
$d = mysqli_real_escape_string($conn, $d);
$l = mysqli_real_escape_string($conn, $l);
if($_POST['original'] == "none") {
$sql = "INSERT INTO `" . $database . "`.`openappstore` (`app`, `summary`, `link`, `screenshots`) VALUES ('". $a . "', '" . $d . "', '" . $l . "', '" . $fileString . "');";
} else {
if(!isset($version)) {
die("Must have a version #");
}
$sql = "INSERT INTO `openappstoreversions` (appid,version,changes,file) VALUES ('" . $original . "','" . $version . "','" . $changes . "','" . $l . "');";
}
if ($conn->query($sql) === TRUE) {
//echo "Database created successfully";
} else {
echo "Error creating database: " . $conn->error;
}
$conn->close();
header("Location: index.php?success=1");
?>