<?php
session_start();
include("config.php");

if (isset($_SESSION['user_name']) && $_FILES['fileupload']['name'] != '') {
    $picname = time() . "_" . $_FILES['fileupload']['name'];
    $desc = mysqli_real_escape_string($conn, $_POST['description']);
    $vis = $_POST['visibility'];
    $u_name = $_SESSION['user_name'];

    if (move_uploaded_file($_FILES['fileupload']['tmp_name'], "upload/" . $picname)) {
        $sql = "INSERT INTO gallery (picname, description, visibility_type, user_id) VALUES ('$picname', '$desc', '$vis', '$u_name')";
        if (mysqli_query($conn, $sql)) { echo "success"; }
    }
}
?>