-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
30 lines (24 loc) · 981 Bytes
/
Copy pathupload.php
File metadata and controls
30 lines (24 loc) · 981 Bytes
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
<?php
// Include the database connection
require 'db.php';
session_start(); // Start session to access the logged-in user's data
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = $_POST['title'];
$description = $_POST['description'];
$type = $_POST['type'];
$image = null;
if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) {
$image = uniqid() . '_' . $_FILES['image']['name'];
move_uploaded_file($_FILES['image']['tmp_name'], 'uploads/' . $image);
}
// Get the logged-in user's ID from session
$user_id = $_SESSION['user_id']; // Assuming user_id is stored in session
// Prepare the SQL statement
$stmt = $conn->prepare('INSERT INTO posts (title, description, type, image, user_id) VALUES (?, ?, ?, ?, ?)');
$stmt->bind_param('ssssi', $title, $description, $type, $image, $user_id); // Added user_id
$stmt->execute();
$stmt->close();
echo 'Success';
}
$conn->close();
?>