[insert_php]
$target_dir = “uploads/”;
$path = $_FILES[“fileToUpload”][“name”];
$e = pathinfo($path, PATHINFO_EXTENSION);
$target_file = $target_dir . uniqid() ;
$uploadOk = 1;
$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image;
$valid_exts = array(
‘jpeg’,
‘jpg’,
‘png’,
‘gif’
);
$sizes = array(
652 => 489,
326 => 244
);
$ext = strtolower($e);
if (in_array(strtolower($ext), $valid_exts)) {
/* resize image */
$paths[] = null;
$count = 0;
foreach ($sizes as $width => $height) {
$count++;
/* Get original image x y*/
list($w, $h) = getimagesize($_FILES[‘fileToUpload’][‘tmp_name’]);
/* calculate new image size with ratio */
$ratio = max($width / $w, $height / $h);
$h = ceil($height / $ratio);
$x = ($w – $width / $ratio) / 2;
$w = ceil($width / $ratio);
/* new file name */
$path = $target_file . ($count == 2 ? ‘_thumbnail’ : “”) . “.” . $ext ;
/* read binary data from image file */
$imgString = file_get_contents($_FILES[‘fileToUpload’][‘tmp_name’]);
/* create image from string */
$image = imagecreatefromstring($imgString);
$tmp = imagecreatetruecolor($width, $height);
imagecopyresampled($tmp, $image, 0, 0, $x, 0, $width, $height, $w, $h);
/* Save image */
switch ($_FILES[‘fileToUpload’][‘type’]) {
case ‘image/jpeg’:
imagejpeg($tmp, $path, 100);
break;
case ‘image/png’:
imagepng($tmp, $path, 0);
break;
case ‘image/gif’:
imagegif($tmp, $path);
break;
default:
exit;
break;
}
array_push($paths, $path);
/* cleanup memory */
imagedestroy($image);
imagedestroy($tmp);
}
}
if (isset($_POST[“submit”])) {
$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.”;
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo “Sorry, file already exists.”;
$uploadOk = 0;
}
// Check file size
if ($_FILES[“fileToUpload”][“size”] > (5 * 1024 * 1024)) {
echo “Sorry, your file is too large.”;
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo “Sorry, your file was not uploaded.”;
// if everything is ok, try to upload file
} else {
date_default_timezone_set(‘America/Chicago’);
$date = current_time(‘mysql’);
$GLOBALS[‘wpdb’]->insert(‘groups’, array(
‘location_id’ => 6,
‘name’ => stripslashes_deep($_POST[‘groupname’]),
‘photo_url’ => $paths[1],
‘photo_thumbnail’ => $paths[2],
‘time’ => $_POST[‘time’],
‘room’ => $_POST[‘room’],
‘created_at’ => $date
), array(
‘%d’,
‘%s’,
‘%s’,
‘%s’,
‘%d’,
‘%d’
));
$rank = ‘unknown’;
set_query_var(@rank, 0);
$sql_query = “SELECT @rank:=@rank+1 AS rank, id FROM `groups` ORDER BY time DESC”;
$ranked_results = $GLOBALS[‘wpdb’]->get_results($sql_query);
$rank = 1;
foreach ($ranked_results as $r) {
if ($r->id == $GLOBALS[‘wpdb’]->insert_id) {
break;
}
$rank++;
}
$new_id = $GLOBALS[‘wpdb’]->insert_id;
if (move_uploaded_file($_FILES[“fileToUpload”][“tmp_name”], $target_file)) {
header(“Location: https://greenvilleescaperoom.com/our-guests?id=” . $new_id . “&room=” . $_POST[‘room’]);
die();
} else {
echo “Sorry, there was an error uploading your file.”;
}
}
[/insert_php]