Start tracking comments
[pics.git] / upload.php
index 295f420..d69e283 100644 (file)
@@ -17,6 +17,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
     $mime_type = $images['type'][$i];
     $tmp_file = $images['tmp_name'][$i];
     $error = $images['error'][$i];
+    if($error != '0') {
+      http_response_code(400);
+      die('Upload error');
+    }
     $size = $images['size'][$i];
     // strip EXIF
     $img = new Imagick($tmp_file);
@@ -43,6 +47,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
   $post_stmt->bindValue(':id', $post_id);
   $post_stmt->bindValue(':user', $user);
   $post_stmt->bindValue(':time', $post_time);
+
+  $comment_stmt = $db->prepare('INSERT into comments VALUES (:id, :post_id, :body)');
+  $comment_stmt->bindValue(':id', uuid_v4());
+  $comment_stmt->bindValue(':post_id', $post_id);
+  $comment_stmt->bindValue(':body', $_POST['comment'] ?? '');
+  $comment_stmt->execute();
   $post_stmt->execute();
 
   $db->exec('COMMIT');
@@ -54,7 +64,7 @@ echo '
        <label>Pick Images:<input type="file" id="upload" name="image[]" multiple>
         </input></label>
         <br/>
-        <textarea id="comment" name="comment">Title/comment your post</textarea>
+        <textarea id="comment" name="comment" placeholder="Title/comment your post"></textarea>
         <br/>
        <input type="submit" value="Upload"/>
       </form>