-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnapshot.php
More file actions
75 lines (69 loc) · 2.3 KB
/
snapshot.php
File metadata and controls
75 lines (69 loc) · 2.3 KB
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
<?php
require_once('./config/include.php');
require_once('./src/validations.php');
require_once('./src/images.php');
require_once('./src/posts_db.php');
require_login('');
$info = $error = $description = $thumbnails = '';
if (is_post_request()) {
if(isset($_POST['submit'])) {
try {
$picture_url = $_POST['pic-url'];
if (isset($_POST['description']) && !empty($_POST['description']))
$description = validate_comment($_POST['description']);
//Save all selected stickers to array
$sticker_ids = parse_sticker_ids($_POST);
$sticker_count = count($sticker_ids);
// If at least one sticker selected, combine images
if ($sticker_count > 0 && isset($picture_url) && !empty($picture_url)) {
$original_temp_path = prepare_image($picture_url);
$image_relative_path = save_image($original_temp_path, $sticker_ids);
create_post($dbc, $image_relative_path, $_SESSION['user_id'], $description, 1);
$qparam = http_build_query(array('info' => 'uploaded'));
header('Location: upload.php?' . $qparam);
}
else {
$info = "Error: No stickers selected. Please try again!";
echo get_template('upload.php', array(
'title' => 'New post',
'info' => $info,
'error' => $error,
'thumbnails' => $thumbnails,
));
}
} catch (NoFileProvidedException $e) {
$error = 'There is no file to upload. Please upload an image.';
} catch (TooBigFileException $e) {
$error = 'This file is too big. Please try again.';
} catch (FileNotAllowedException $e) {
$error = 'Oops, invalid filetype. Only jpeg or png files are allowed.';
} catch (ValidationException $e) {
$error = $e->getMessage();
} catch (PDOException $e) {
// $error = "Failed to load the post. Please, try again.";
$error = $e->getMessage();
}
}
if ($error)
echo get_template('upload.php', array(
'title' => 'New post',
'info' => $info,
'error' => $error,
'thumbnails' => $thumbnails,
));
}
if (is_get_request()) {
if (isset($_GET['info']) && $_GET['info'] === 'uploaded') {
$info = 'Uploaded successfully!';
}
echo get_template('upload.php', array(
'title' => 'New post',
'info' => $info,
'error' => $error,
'thumbnails' => $thumbnails,
));
}
// echo '<pre>';
// var_dump($post_result);
// echo '</pre>';
?>