735f96aa044beb7a136c2d8a4ce203b965bacc7f
3 require_once __DIR__
. '/db.php';
4 require_once __DIR__
. '/auth.php';
5 require_once __DIR__
. '/uuid.php';
7 if ($_SERVER['REQUEST_METHOD'] === 'POST') {
10 $db->exec('BEGIN TRANSACTION');
13 $images = $_FILES['image'];
14 $num_files = count($images['name']);
15 for ($i = 0; $i < $num_files; $i++
) {
16 $name = $images['name'][$i];
17 $mime_type = $images['type'][$i];
18 $tmp_file = $images['tmp_name'][$i];
19 $error = $images['error'][$i];
21 http_response_code(400);
24 $size = $images['size'][$i];
26 $img = new Imagick($tmp_file);
27 // keep ICC for quality
28 $profiles = $img->getImageProfiles("icc", true);
30 if(!empty($profiles)) {
31 $img->profileImage('icc', $profiles['icc']);
34 $file_b64 = base64_encode($img->getImageBlob());
36 $upload_stmt = $db->prepare('INSERT into pics values (:id, :post_id, :mime_type, :b64_bytes)');
37 $upload_stmt->bindValue(':id', $pic_id);
38 $upload_stmt->bindValue(':post_id', $post_id);
39 $upload_stmt->bindValue(':mime_type', $mime_type);
40 $upload_stmt->bindValue(':b64_bytes', $file_b64);
41 $upload_stmt->execute();
43 echo "<img src='data:{$mime_type};base64,{$file_b64}' alt='$name'/>";
46 $post_stmt = $db->prepare('INSERT into posts VALUES(:id, :user, :time)');
47 $post_stmt->bindValue(':id', $post_id);
48 $post_stmt->bindValue(':user', $user);
49 $post_stmt->bindValue(':time', $post_time);
50 $post_stmt->execute();
57 <form enctype="multipart/form-data" method="POST" action="upload.php">
58 <label>Pick Images:<input type="file" id="upload" name="image[]" multiple>
61 <textarea id="comment" name="comment">Title/comment your post</textarea>
63 <input type="submit" value="Upload"/>