-
Notifications
You must be signed in to change notification settings - Fork 0
/
emoji-new.php
157 lines (137 loc) · 5.21 KB
/
emoji-new.php
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
// Initialize SQLite3 database
$database = new SQLite3('emoji.db');
// Create emoji table if it doesn't exist
$database->exec('CREATE TABLE IF NOT EXISTS emoji (
id INTEGER PRIMARY KEY AUTOINCREMENT,
folder_name TEXT,
image_path TEXT,
description TEXT
)');
// Check if the user is logged in
if (!isset($_COOKIE['token'])) {
echo "ログインされていません。<br>3秒後にホームに戻ります。";
echo '<meta http-equiv="Refresh" content="3; url=index.php">';
exit;
}
// Initialize the variable
$validationPassed = false;
$validationErrors = [];
// Check if form is submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Validate and process form data
$folderName = $_POST['folder_name'] ?? '';
$imageFiles = $_FILES['image_file'] ?? null;
$imageDescriptions = $_POST['image_description'] ?? [];
// Validate folder name
if (empty($folderName)) {
$validationErrors[] = 'フォルダの名前を入力してください。';
}
// Validate image files
if (!isset($imageFiles) || !is_array($imageFiles['tmp_name'])) {
$validationErrors[] = '画像ファイルを選択してください。';
} else {
$fileCount = count($imageFiles['tmp_name']);
if ($fileCount > 30) {
$validationErrors[] = '最大30枚の画像ファイルを選択してください。';
}
// Create folder based on folder name if it doesn't exist
$folderPath = 'emoji/' . $folderName;
if (!is_dir($folderPath)) {
if (!mkdir($folderPath, 0777, true)) {
// Failed to create directory
$validationErrors[] = 'フォルダを作成できませんでした。';
}
}
// Loop through each uploaded file
for ($i = 0; $i < $fileCount; $i++) {
$tmpName = $imageFiles['tmp_name'][$i];
$fileName = $imageFiles['name'][$i];
$imageDescription = $imageDescriptions[$i] ?? '';
// Move uploaded file to the folder with the same name as folder name
move_uploaded_file($tmpName, $folderPath . '/' . $fileName);
// Insert entry into emoji table
$statement = $database->prepare('INSERT INTO emoji (folder_name, image_path, description) VALUES (:folder_name, :image_path, :description)');
$statement->bindValue(':folder_name', $folderName, SQLITE3_TEXT);
$statement->bindValue(':image_path', $folderPath . '/' . $fileName, SQLITE3_TEXT);
$statement->bindValue(':description', $imageDescription, SQLITE3_TEXT);
$statement->execute();
}
}
// If no validation errors, set $validationPassed to true
if (empty($validationErrors)) {
$validationPassed = true;
}
// If everything is valid, display success message
if ($validationPassed) {
echo "絵文字の申請が完了しました。<br>3秒後にホームに戻ります。";
echo '<meta http-equiv="Refresh" content="3; url=index.php">';
exit;
} else {
// Display error messages
echo "エラーが発生しました。入力内容を確認してください。";
print_r($validationErrors);
// Additional error handling and message display can be added here
}
}
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rosekey Portal - 絵文字申請</title>
<style>
/* Your modern CSS styles here */
/* Example: */
form {
max-width: 600px;
margin: 20px auto;
padding: 20px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
label {
display: block;
margin-bottom: 10px;
}
input[type="file"],
input[type="text"],
textarea {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type="submit"] {
background-color: #4caf50;
color: #fff;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
input[type="submit"]:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<?php include 'header.php'; ?>
<!-- Emoji Submission Form -->
<form action="emoji-new.php" method="post" enctype="multipart/form-data">
<label for="folder_name">フォルダの名前 (英語のみ)</label>
<input type="text" name="folder_name" required><br>
<label for="image_file">画像ファイル (30MBまでのPNG, JPG, JPEG、最大30枚)</label>
<input type="file" name="image_file[]" accept=".png, .jpg, .jpeg, .gif, .webp" multiple required><br>
<label for="image_description[]">説明</label>
<textarea name="image_description[]" required></textarea><br>
<input type="submit" value="申請する">
</form>
<?php include 'footer.php'; ?>
</body>
</html>