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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<div class="relative z-10 flex items-center justify-center h-full p-8">
<div class="max-w-4xl w-full">
<!-- Main Upload Area -->
<div class="bg-white/10 backdrop-blur-lg rounded-2xl border border-white/20 p-6 shadow-2xl animate-scale-in">
<!-- Upload Zone -->
<div id="dropZone" class="border-2 border-dashed border-blue-300/50 rounded-xl p-8 text-center transition-all duration-500 hover:border-blue-400/80 hover:bg-blue-500/10 cursor-pointer min-h-96 relative group hover:shadow-xl hover:shadow-blue-500/20">
<input type="file" id="fileInput" class="hidden" multiple accept="image/*" required>
<!-- Empty State -->
<div id="emptyState" class="flex flex-col items-center justify-center h-full animate-bounce-gentle">
<div class="w-20 h-20 bg-gradient-to-br from-blue-500 to-blue-700 rounded-full flex items-center justify-center mb-6 shadow-lg animate-pulse-glow">
<svg class="w-10 h-10 text-white drop-shadow-lg" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
</svg>
</div>
<h3 class="text-2xl font-semibold text-blue-600 mb-3 animate-fade-in-up">Drop your images here</h3>
<p class="text-blue-200 mb-6 animate-fade-in-up-delay">JPG, PNG, GIF, WebP supported</p>
<button class="bg-gradient-to-r from-blue-600 to-blue-700 hover:from-blue-700 hover:to-blue-800 text-white font-semibold py-3 px-8 rounded-lg transition-all duration-300 transform hover:scale-105 shadow-lg hover:shadow-blue-500/50 animate-fade-in-final">
Select Images
</button>
</div>
<!-- Images Container -->
<div id="imageContainer" class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4 hidden">
<!-- Images will be inserted here -->
</div>
<!-- Add More Button -->
<button id="addMoreBtn" class="hidden absolute top-4 right-4 bg-blue-600 hover:bg-blue-700 text-white p-3 rounded-full transition-all duration-300 transform hover:scale-110 shadow-lg hover:shadow-blue-500/50 animate-float">
<svg class="w-6 h-6 drop-shadow-lg" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
</button>
</div>
<!-- Action Buttons -->
<div id="actionButtons" class="hidden mt-6 flex justify-between items-center animate-slide-up">
<button id="clearAll" class="text-red-400 hover:text-red-300 transition-all duration-300 flex items-center space-x-2 hover:bg-red-500/10 px-4 py-2 rounded-lg transform hover:scale-105">
<svg class="w-5 h-5 drop-shadow-lg" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
</svg>
<span>Clear All</span>
</button>
<button id="uploadBtn" class="bg-gradient-to-r from-blue-600 to-blue-700 hover:from-blue-700 hover:to-blue-800 text-white font-semibold py-3 px-8 rounded-lg transition-all duration-300 transform hover:scale-105 shadow-lg hover:shadow-blue-500/50">
Upload Images
</button>
</div>
<!-- Upload Progress -->
<div id="uploadProgress" class="hidden mt-6 animate-fade-in">
<div class="flex items-center justify-between mb-3">
<span class="text-white font-medium">Uploading images...</span>
<span id="progressText" class="text-blue-200 font-semibold">0%</span>
</div>
<div class="w-full bg-white/20 rounded-full h-3 overflow-hidden">
<div id="progressBar" class="h-full bg-gradient-to-r from-blue-500 to-blue-600 rounded-full transition-all duration-500 w-0 shadow-lg animate-pulse-glow"></div>
</div>
</div>
<!-- Error Message -->
<div id="errorMessage" class="hidden mt-4 p-4 bg-red-500/20 border border-red-500/50 rounded-lg animate-shake">
<div class="flex items-center space-x-2">
<svg class="w-5 h-5 text-red-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
<span class="text-red-300 font-medium" id="errorText"></span>
</div>
</div>
</div>
</div>
</div>
<script>
let selectedFiles = [];
let draggedElement = null;
const dropZone = document.getElementById('dropZone');
const fileInput = document.getElementById('fileInput');
const emptyState = document.getElementById('emptyState');
const imageContainer = document.getElementById('imageContainer');
const addMoreBtn = document.getElementById('addMoreBtn');
const actionButtons = document.getElementById('actionButtons');
const clearAllBtn = document.getElementById('clearAll');
const uploadBtn = document.getElementById('uploadBtn');
const uploadProgress = document.getElementById('uploadProgress');
const progressBar = document.getElementById('progressBar');
const progressText = document.getElementById('progressText');
const errorMessage = document.getElementById('errorMessage');
const errorText = document.getElementById('errorText');
// Security: Only accept images
const allowedTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/webp', 'image/svg+xml'];
const maxFileSize = 10 * 1024 * 1024; // 10MB per file
const maxFiles = 20; // Maximum 20 files
// Click to select files
dropZone.addEventListener('click', (e) => {
if (e.target.closest('#addMoreBtn') || e.target.closest('.image-item')) return;
fileInput.click();
});
addMoreBtn.addEventListener('click', (e) => {
e.stopPropagation();
fileInput.click();
});
// Enhanced drag and drop with security
dropZone.addEventListener('dragover', (e) => {
e.preventDefault();
if (!e.dataTransfer.types.includes('Files')) return;
dropZone.classList.add('border-blue-400/80', 'bg-blue-500/20', 'shadow-xl', 'shadow-blue-500/30');
});
dropZone.addEventListener('dragleave', (e) => {
e.preventDefault();
if (e.relatedTarget && dropZone.contains(e.relatedTarget)) return;
dropZone.classList.remove('border-blue-400/80', 'bg-blue-500/20', 'shadow-xl', 'shadow-blue-500/30');
});
dropZone.addEventListener('drop', (e) => {
e.preventDefault();
dropZone.classList.remove('border-blue-400/80', 'bg-blue-500/20', 'shadow-xl', 'shadow-blue-500/30');
if (e.dataTransfer.files.length > 0) {
const files = Array.from(e.dataTransfer.files);
handleFiles(files);
}
});
fileInput.addEventListener('change', (e) => {
const files = Array.from(e.target.files);
handleFiles(files);
});
function handleFiles(files) {
hideError();
// Security validation
const validationResult = validateFiles(files);
if (!validationResult.valid) {
showError(validationResult.message);
return;
}
files.forEach(file => {
if (!selectedFiles.some(f => f.name === file.name && f.size === file.size)) {
selectedFiles.push(file);
}
});
displayFiles();
}
function validateFiles(files) {
// Check file count
if (selectedFiles.length + files.length > maxFiles) {
return { valid: false, message: `Maximum ${maxFiles} files allowed` };
}
// Check each file
for (let file of files) {
// Check file type
if (!allowedTypes.includes(file.type.toLowerCase())) {
return { valid: false, message: `Only image files are allowed (JPG, PNG, GIF, WebP, SVG)` };
}
// Check file size
if (file.size > maxFileSize) {
return { valid: false, message: `File "${file.name}" is too large. Maximum size is 10MB` };
}
// Check file name for security
if (file.name.includes('../') || file.name.includes('..\\')) {
return { valid: false, message: `Invalid file name: "${file.name}"` };
}
}
return { valid: true };
}
function displayFiles() {
if (selectedFiles.length > 0) {
emptyState.classList.add('hidden');
imageContainer.classList.remove('hidden');
addMoreBtn.classList.remove('hidden');
actionButtons.classList.remove('hidden');
imageContainer.innerHTML = '';
selectedFiles.forEach((file, index) => {
const imageItem = createImageItem(file, index);
imageContainer.appendChild(imageItem);
});
} else {
emptyState.classList.remove('hidden');
imageContainer.classList.add('hidden');
addMoreBtn.classList.add('hidden');
actionButtons.classList.add('hidden');
}
}
function createImageItem(file, index) {
const div = document.createElement('div');
div.className = 'image-item relative bg-white/10 rounded-xl overflow-hidden cursor-move group border-2 border-transparent hover:border-blue-400/80 transition-all duration-300 transform hover:scale-105 hover:shadow-lg hover:shadow-blue-500/30 animate-scale-in';
div.draggable = true;
div.dataset.index = index;
div.style.animationDelay = `${index * 0.1}s`;
const img = document.createElement('img');
img.className = 'w-full h-32 object-cover transition-transform duration-300 group-hover:scale-110';
const reader = new FileReader();
reader.onload = (e) => {
img.src = e.target.result;
};
reader.readAsDataURL(file);
const overlay = document.createElement('div');
overlay.className = 'absolute inset-0 bg-black/60 opacity-0 group-hover:opacity-100 transition-all duration-300 flex items-center justify-center backdrop-blur-sm';
const removeBtn = document.createElement('button');
removeBtn.className = 'bg-red-500/80 hover:bg-red-600 text-white p-2 rounded-full transition-all duration-200 transform hover:scale-110 shadow-lg glow-icon';
removeBtn.innerHTML = '<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>';
removeBtn.onclick = (e) => {
e.stopPropagation();
removeFile(index);
};
const fileName = document.createElement('div');
fileName.className = 'absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/80 to-transparent text-white text-xs p-3 truncate';
fileName.textContent = file.name;
// Drag indicator
const dragIndicator = document.createElement('div');
dragIndicator.className = 'absolute top-2 right-2 text-white/60 opacity-0 group-hover:opacity-100 transition-opacity duration-300';
dragIndicator.innerHTML = '<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"/></svg>';
overlay.appendChild(removeBtn);
div.appendChild(img);
div.appendChild(overlay);
div.appendChild(fileName);
div.appendChild(dragIndicator);
// Enhanced drag events
div.addEventListener('dragstart', (e) => {
draggedElement = div;
div.classList.add('opacity-50', 'scale-95');
});
div.addEventListener('dragend', (e) => {
div.classList.remove('opacity-50', 'scale-95');
draggedElement = null;
});
div.addEventListener('dragover', (e) => {
e.preventDefault();
if (draggedElement && draggedElement !== div) {
div.classList.add('ring-2', 'ring-blue-400', 'ring-opacity-50');
}
});
div.addEventListener('dragleave', (e) => {
div.classList.remove('ring-2', 'ring-blue-400', 'ring-opacity-50');
});
div.addEventListener('drop', (e) => {
e.preventDefault();
div.classList.remove('ring-2', 'ring-blue-400', 'ring-opacity-50');
if (draggedElement && draggedElement !== div) {
const draggedIndex = parseInt(draggedElement.dataset.index);
const targetIndex = parseInt(div.dataset.index);
// Reorder files
const draggedFile = selectedFiles[draggedIndex];
selectedFiles.splice(draggedIndex, 1);
selectedFiles.splice(targetIndex, 0, draggedFile);
displayFiles();
}
});
return div;
}
function removeFile(index) {
selectedFiles.splice(index, 1);
displayFiles();
}
function showError(message) {
errorText.textContent = message;
errorMessage.classList.remove('hidden');
setTimeout(() => hideError(), 5000);
}
function hideError() {
errorMessage.classList.add('hidden');
}
clearAllBtn.addEventListener('click', () => {
selectedFiles = [];
displayFiles();
fileInput.value = '';
hideError();
});
uploadBtn.addEventListener('click', () => {
if (selectedFiles.length === 0) return;
uploadProgress.classList.remove('hidden');
uploadBtn.disabled = true;
uploadBtn.textContent = 'Uploading...';
// Simulate upload with progress
let progress = 0;
const interval = setInterval(() => {
progress += Math.random() * 12;
if (progress >= 100) {
progress = 100;
clearInterval(interval);
setTimeout(() => {
uploadProgress.classList.add('hidden');
uploadBtn.disabled = false;
uploadBtn.textContent = 'Upload Complete!';
uploadBtn.className = uploadBtn.className.replace('from-blue-600 to-blue-700', 'from-green-600 to-green-700');
setTimeout(() => {
uploadBtn.textContent = 'Upload Images';
uploadBtn.className = uploadBtn.className.replace('from-green-600 to-green-700', 'from-blue-600 to-blue-700');
}, 3000);
}, 600);
}
progressBar.style.width = progress + '%';
progressText.textContent = Math.round(progress) + '%';
}, 150);
});
</script>