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];
20 $size = $images['size'][$i];
22 $img = new Imagick($tmp_file);
23 // keep ICC for quality
24 $profiles = $img->getImageProfiles("icc", true);
26 if(!empty($profiles)) {
27 $img->profileImage('icc', $profiles['icc']);
30 $file_b64 = base64_encode($img->getImageBlob());
32 $upload_stmt = $db->prepare('INSERT into pics values (:id, :post_id, :mime_type, :b64_bytes)');
33 $upload_stmt->bindValue(':id', $pic_id);
34 $upload_stmt->bindValue(':post_id', $post_id);
35 $upload_stmt->bindValue(':mime_type', $mime_type);
36 $upload_stmt->bindValue(':b64_bytes', $file_b64);
37 $upload_stmt->execute();
39 echo "<img src='data:{$mime_type};base64,{$file_b64}' alt='$name'/>";
42 $post_stmt = $db->prepare('INSERT into posts VALUES(:id, :user, :time)');
43 $post_stmt->bindValue(':id', $post_id);
44 $post_stmt->bindValue(':user', $user);
45 $post_stmt->bindValue(':time', $post_time);
46 $post_stmt->execute();
53 <form enctype="multipart/form-data" method="POST" action="upload.php">
54 <label>Pick Images:<input type="file" id="upload" name="image[]" multiple>
57 <textarea id="comment" name="comment">Title/comment your post</textarea>
59 <input type="submit" value="Upload"/>