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
|
<?php
define('CANONICAL', 'https://cflems.net/'); // for nav
define('UPLOADS_DIR', 'uploads/');
define('UPLOAD_BASE_URL', 'https://i.fle.ms/');
function handle_upload() {
global $error;
if (!isset($_FILES['image'])) {
$error = 'Please select an image.';
return;
}
$tmp_file = $_FILES['image']['tmp_name'];
try {
$image_type = exif_imagetype($tmp_file);
} catch (Exception $_) {
$image_type = false;
}
$disallowed_types = array(
IMAGETYPE_SWF, IMAGETYPE_SWC, IMAGETYPE_UNKNOWN);
if ($image_type === false || in_array($image_type, $disallowed_types)) {
$error = 'The uploaded file is not an image.';
return;
}
$slug = substr(hash_file('sha256', $tmp_file), -16);
$ext = image_type_to_extension($image_type);
$ext = $ext ? $ext : '.png';
$file_name = $slug . $ext;
if (!is_dir(UPLOADS_DIR))
mkdir(UPLOADS_DIR);
if (!file_exists(UPLOADS_DIR . $file_name))
move_uploaded_file($tmp_file, UPLOADS_DIR . $file_name);
$uploaded_url = UPLOAD_BASE_URL . $file_name;
header('Location: ' . UPLOAD_BASE_URL . $file_name);
die($uploaded_url);
}
if (isset($_POST['upload'])) handle_upload();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>cflems's images</title>
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0" />
<meta name="author" content="Carson Fleming" />
<meta name="description" content="cflems's image storage facility." />
<meta property="og:site_name" content="cflems.net" />
<meta property="og:title" content="cflems's images" />
<meta property="og:description" content="cflems's image storage facility." />
<meta property="og:url" content="https://img.cflems.net/" />
<meta property="og:type" content="website" />
<meta property="og:image" content="https://cdn.cflems.net/assets/cflemse5bd6ff0.webp" />
<meta property="og:image:width" content="256" />
<meta property="og:image:height" content="256" />
<meta property="og:locale" content="en_US" />
<link rel="canonical" href="https://img.cflems.net/" />
<link rel="icon" type="image/svg+xml" href="https://cdn.cflems.net/assets/cflemsffd498eb.svg" />
<link rel="stylesheet" type="text/css" href="https://cflems.net/css/fonts.css" />
<link rel="stylesheet" type="text/css" href="https://cflems.net/css/nav.css" />
<link rel="stylesheet" type="text/css" href="https://cflems.net/css/style.css" />
<script type="text/javascript" src="https://cflems.net/js/nav.js" defer="defer"></script>
</head>
<body>
<?php
require(__DIR__.'/../cflems.net/shared/nav.php');
?>
<header>
<h1>
<span class="name">cflems's</span>
<span class="emdash"></span>
</h1>
<h2 style="color: var(--text-color-tertiary);">Images</h2>
<p>Arbitrary image storage facility.</p>
</header>
<section>
<div class="item">
<form class="left" action="/" method="post" enctype="multipart/form-data">
<h2>Upload Image</h2>
<h3>Select an image from your computer.</h3>
<p>
<input type="file" name="image" accept="image/*" required="required" />
</p>
<?php
if (isset($error)) {
?>
<p class="error" style="color: #dd2255; font-weight: 700;">Error: <?=htmlentities($error);?></p>
<?php
}
?>
<p>
<input type="submit" name="upload" value="Upload" />
</p>
</form>
<div class="right">
<img src="https://cdn.cflems.net/penguins/photog.png" alt="Photographer Penguin" />
</div>
</div>
</section>
<?php
require(__DIR__.'/../cflems.net/shared/footer.php');
?>
</body>
</html>
|