-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload_attachment.php
More file actions
62 lines (51 loc) · 1.74 KB
/
upload_attachment.php
File metadata and controls
62 lines (51 loc) · 1.74 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
session_start();
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
header("Location: login.php");
exit();
}
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "demo";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Bağlantı hatası: " . $conn->connect_error);
}
$response = array();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$templateId = $_POST['attachTemplateId'];
$attachmentPath = null;
if (isset($_FILES['attachmentFile']) && $_FILES['attachmentFile']['error'] === UPLOAD_ERR_OK) {
$attachmentTmpPath = $_FILES['attachmentFile']['tmp_name'];
$attachmentName = basename($_FILES['attachmentFile']['name']);
$attachmentDir = 'uploads/';
$attachmentPath = $attachmentDir . $attachmentName;
if (!move_uploaded_file($attachmentTmpPath, $attachmentPath)) {
$response['success'] = false;
$response['error'] = "Dosya yükleme hatası.";
echo json_encode($response);
exit();
}
// Ek dosyayı veritabanına kaydetme
$sql = "UPDATE mails SET m_kaynak = ? WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("si", $attachmentPath, $templateId);
if ($stmt->execute()) {
$response['success'] = true;
} else {
$response['success'] = false;
$response['error'] = $conn->error;
}
$stmt->close();
} else {
$response['success'] = false;
$response['error'] = "Dosya yükleme hatası.";
}
} else {
$response['success'] = false;
$response['error'] = "Invalid request method.";
}
$conn->close();
echo json_encode($response);
?>