-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload-image.php
More file actions
262 lines (234 loc) · 8.27 KB
/
upload-image.php
File metadata and controls
262 lines (234 loc) · 8.27 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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?php
include_once("config.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Upload Image</title>
<style>
body {
font-family: Arial, sans-serif;
background: #f2f2f2;
padding: 2rem;
display: flex;
justify-content: center;
}
.upload-container {
background: #fff;
padding: 2rem;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
width: 400px;
text-align: center;
}
.drop-zone {
border: 2px dashed #bbb;
border-radius: 6px;
padding: 2rem;
background: #fafafa;
cursor: pointer;
transition: background 0.3s;
}
.drop-zone.dragover {
background: #e8f0fe;
border-color: #4285f4;
}
input[type="file"] {
display: none;
}
#preview {
margin-top: 1rem;
max-width: 100%;
display: none;
border-radius: 6px;
border: 1px solid #ccc;
}
.submit-btn {
margin-top: 1rem;
background-color: #4CAF50;
color: white;
padding: 0.6rem 1.2rem;
border: none;
border-radius: 5px;
cursor: pointer;
}
.submit-btn:hover {
background-color: #45a049;
}
.form-group {
margin-top: 1rem;
text-align: left;
}
.form-group label {
display: block;
margin-bottom: 0.2rem;
font-weight: bold;
}
.form-group input {
width: 100%;
padding: 0.4rem;
border: 1px solid #ccc;
border-radius: 5px;
}
/* Style the select */
#licenseSelect {
width: 100%;
padding: 0.4rem;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 1rem;
font-family: Arial, sans-serif;
box-sizing: border-box;
appearance: none; /* Remove default arrow for some browsers */
background: white url('data:image/svg+xml;utf8,<svg fill="gray" height="16" viewBox="0 0 24 24" width="16" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>') no-repeat right 0.75rem center;
background-size: 1em;
cursor: pointer;
transition: border-color 0.2s ease;
}
#licenseSelect:focus {
outline: none;
border-color: #4285f4;
box-shadow: 0 0 3px #4285f4;
}
/* Style the custom license input */
#customLicense {
width: 100%;
padding: 0.4rem;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 1rem;
font-family: Arial, sans-serif;
box-sizing: border-box;
}
#customLicense:focus {
outline: none;
border-color: #4285f4;
box-shadow: 0 0 3px #4285f4;
}
</style>
</head>
<body>
<div class="upload-container">
<h2>Upload Image</h2>
<form id="uploadForm" enctype="multipart/form-data">
<div class="drop-zone" id="dropZone">
<p>Drag & drop image here or click to select</p>
<input type="file" name="file_input" id="file_input" accept="image/*" />
</div>
<img id="preview" alt="Image Preview" />
<div class="form-group">
<label for="licenseSelect">License Type</label>
<select name="license" id="licenseSelect" required>
<option value="">Lizenz auswählen ...</option>
<option value="CC BY">Creative Commons Attribution (CC BY)</option>
<option value="CC BY-SA">Creative Commons ShareAlike (CC BY-SA)</option>
<option value="CC BY-ND">Creative Commons NoDerivs (CC BY-ND)</option>
<option value="CC BY-NC">Creative Commons NonCommercial (CC BY-NC)</option>
<option value="MIT">MIT License</option>
<option value="GPL">GNU GPL</option>
<option value="Apache">Apache License 2.0</option>
<option value="Other">Andere Lizenz (bitte spezifizieren)</option>
</select>
<input type="text" name="custom_license" id="custom_license" placeholder="Enter custom license" style="display:none; margin-top: 0.5rem;" />
</div>
<div class="form-group">
<label for="created_by">Created By</label>
<input type="text" name="created_by" id="created_by" />
</div>
<div class="form-group">
<label for="copyright">Copyright</label>
<input type="text" name="copyright" id="copyright" />
</div>
<div class="form-group">
<label for="alt_text">Alternate Text</label>
<input type="text" name="alt_text" id="alt_text" />
</div>
<div class="form-group">
<label for="focus_x">Focus X (0–10000)</label>
<input type="number" step="0.01" min="0" max="1" name="focus_x" id="focus_x" />
</div>
<div class="form-group">
<label for="focus_y">Focus Y (0–10000)</label>
<input type="number" step="0.01" min="0" max="1" name="focus_y" id="focus_y" />
</div>
<div class="form-group">
<label for="user_id">User ID</label>
<input type="text" name="user_id" id="user_id" />
</div>
<input type="submit" value="Upload" class="submit-btn" />
</form>
</div>
<script>
const dropZone = document.getElementById('dropZone');
const fileInput = document.getElementById('file_input');
const preview = document.getElementById('preview');
dropZone.addEventListener('click', () => fileInput.click());
dropZone.addEventListener('dragover', (e) => {
e.preventDefault();
dropZone.classList.add('dragover');
});
dropZone.addEventListener('dragleave', () => dropZone.classList.remove('dragover'));
dropZone.addEventListener('drop', (e) => {
e.preventDefault();
dropZone.classList.remove('dragover');
const file = e.dataTransfer.files[0];
if (file) {
fileInput.files = e.dataTransfer.files;
previewImage(file);
}
});
fileInput.addEventListener('change', () => {
const file = fileInput.files[0];
if (file) previewImage(file);
});
function previewImage(file) {
if (!file.type.startsWith('image/')) return;
const reader = new FileReader();
reader.onload = (e) => {
preview.src = e.target.result;
preview.style.display = 'block';
};
reader.readAsDataURL(file);
}
const licenseSelect = document.getElementById('licenseSelect');
const customLicenseInput = document.getElementById('customLicense');
licenseSelect.addEventListener('change', () => {
if (licenseSelect.value === 'Other') {
customLicenseInput.style.display = 'block';
customLicenseInput.required = true;
}
else {
customLicenseInput.style.display = 'none';
customLicenseInput.required = false;
customLicenseInput.value = '';
}
});
const form = document.getElementById("uploadForm");
form.addEventListener("submit", async (e) => {
e.preventDefault();
const fileInput = document.getElementById("file_input");
if (fileInput.files.length === 0) {
alert("Please select a file.");
return;
}
const formData = new FormData(form); // Includes all form fields
try {
const response = await fetch("<?= $apiBaseUrl ?>/image/upload", {
method: "POST",
body: formData,
credentials: "include" // Send cookies if needed
});
if (response.ok) {
alert("Upload successful!");
} else {
const error = await response.json();
alert("Upload failed: " + (error.error || response.statusText));
}
} catch (err) {
alert("Upload error: " + err.message);
}
});
</script>
</body>
</html>