-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload_html.php
More file actions
47 lines (37 loc) · 1.25 KB
/
upload_html.php
File metadata and controls
47 lines (37 loc) · 1.25 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
<?php
session_start();
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
header("Location: login.php");
exit();
}
$response = array('success' => false);
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['htmlFile'])) {
$file = $_FILES['htmlFile']['tmp_name'];
$htmlContent = file_get_contents($file);
if ($htmlContent !== false) {
$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);
}
$templateName = basename($_FILES['htmlFile']['name'], ".html");
$stmt = $conn->prepare("INSERT INTO mails (m_konu, m_icerik) VALUES (?, ?)");
$stmt->bind_param("sss",$subject, $htmlContent);
if ($stmt->execute()) {
$response['success'] = true;
} else {
$response['error'] = $stmt->error;
}
$stmt->close();
$conn->close();
} else {
$response['error'] = "Dosya içeriği okunamadı.";
}
} else {
$response['error'] = "Geçersiz dosya yükleme isteği.";
}
echo json_encode($response);
?>