Spaces:
Running
Running
Update index.html
Browse files- index.html +111 -1
index.html
CHANGED
|
@@ -1,2 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
-
<!DOCTYPE html><html lang="en" class="h-full"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="/_next/static/css/05190692196f8df0.css" data-precedence="next"/><link rel="preload" as="script" fetchPriority="low" href="/_next/static/chunks/webpack-7b87f3474ed63929.js"/><script src="/_next/static/chunks/4bd1b696-4d35aba5608d50bf.js" async=""></script><script src="/_next/static/chunks/1517-67aa64b6e053732b.js" async=""></script><script src="/_next/static/chunks/main-app-ef8f634a8cf1b257.js" async=""></script><script src="/_next/static/chunks/app/layout-9b65b5f735c10058.js" async=""></script><script src="/_next/static/chunks/8173-5d1b1d037807e4d7.js" async=""></script><script src="/_next/static/chunks/7970-f98ae4bbb489b33e.js" async=""></script><script src="/_next/static/chunks/app/not-found-5aa73a9042ee7fe3.js" async=""></script><script src="/_next/static/chunks/app/share/v2/%5BmessageId%5D/loading-5d8f4e7f05cbaae4.js" async=""></script><script src="/_next/static/chunks/363642f4-fa7e3873b5bfa215.js" async=""></script><script src="/_next/static/chunks/c42d93a8-65985a8c59b3ceb7.js" async=""></script><script src="/_next/static/chunks/751-87eadb259cd4fb14.js" async=""></script><script src="/_next/static/chunks/854-73482541774c4e19.js" async=""></script><script src="/_next/static/chunks/app/share/v2/%5BmessageId%5D/page-4ea1f0875fffb3e3.js" async=""></script><link rel="preload" href="https://plausible.io/js/script.js" as="script"/><title>Image Upload Script</title><meta name="description" content="An app generated on LlamaCoder.io: Image Upload Script"/><meta property="og:title" content="Image Upload Script"/><meta property="og:description" content="An app generated on LlamaCoder.io: Image Upload Script"/><meta property="og:image" content="https://llamacoder.io/api/og?prompt=Image+Upload+Script"/><meta name="twitter:card" content="summary_large_image"/><meta name="twitter:title" content="Image Upload Script"/><meta name="twitter:description" content="An app generated on LlamaCoder.io: Image Upload Script"/><meta name="twitter:image" content="https://llamacoder.io/api/og?prompt=Image+Upload+Script"/><link rel="icon" href="/favicon.ico" type="image/x-icon" sizes="16x16"/><link rel="icon" href="/favicon.ico"/><script src="/_next/static/chunks/polyfills-42372ed130431b0a.js" noModule=""></script></head><body class="flex h-full min-h-full flex-col items-center justify-center"><!--$--><div class="flex h-full w-full grow items-center justify-center"><div class="relative h-full w-full [&_.sp-preview-container]:flex [&_.sp-preview-container]:h-full [&_.sp-preview-container]:w-full [&_.sp-preview-container]:grow [&_.sp-preview-container]:flex-col [&_.sp-preview-container]:justify-center [&_.sp-preview-iframe]:grow sp-wrapper"><div class=" h-full w-full sp-preview sp-stack"><div class=" sp-preview-container"><iframe class=" sp-preview-iframe" title="Sandpack Preview"></iframe><div class=" sp-preview-actions"></div></div></div></div></div><!--/$--><script src="/_next/static/chunks/webpack-7b87f3474ed63929.js" async=""></script><script>(self.__next_f=self.__next_f||[]).push([0])</script><script>self.__next_f.push([1,"1:\"$Sreact.fragment\"\n2:I[53704,[\"7177\",\"static/chunks/app/layout-9b65b5f735c10058.js\"],\"\"]\n3:I[15244,[],\"\"]\n4:I[43866,[],\"\"]\n5:I[48173,[\"8173\",\"static/chunks/8173-5d1b1d037807e4d7.js\",\"7970\",\"static/chunks/7970-f98ae4bbb489b33e.js\",\"4345\",\"static/chunks/app/not-found-5aa73a9042ee7fe3.js\"],\"\"]\n6:I[87970,[\"8173\",\"static/chunks/8173-5d1b1d037807e4d7.js\",\"7970\",\"static/chunks/7970-f98ae4bbb489b33e.js\",\"4345\",\"static/chunks/app/not-found-5aa73a9042ee7fe3.js\"],\"Image\"]\n8:I[86213,[],\"OutletBoundary\"]\na:I[87159,[\"6475\",\"static/chunks/app/share/v2/%5BmessageId%5D/loading-5d8f4e7f05cbaae4.js\"],\"default\"]\nb:I[86213,[],\"MetadataBoundary\"]\nd:I[86213,[],\"ViewportBoundary\"]\nf:I[34835,[],\"\"]\n:HL[\"/_next/static/css/05190692196f8df0.css\",\"style\"]\n"])</script><script>self.__next_f.push([1,"0:{\"P\":null,\"b\":\"V0OA5wep7lMkB6GvCl9Gm\",\"p\":\"\",\"c\":[\"\",\"share\",\"v2\",\"KdSoaXpRW_pDsD-9\"],\"i\":false,\"f\":[[[\"\",{\"children\":[\"share\",{\"children\":[\"v2\",{\"children\":[[\"messageId\",\"KdSoaXpRW_pDsD-9\",\"d\"],{\"children\":[\"__PAGE__\",{}]}]}]}]},\"$undefined\",\"$undefined\",true],[\"\",[\"$\",\"$1\",\"c\",{\"children\":[[[\"$\",\"link\",\"0\",{\"rel\":\"stylesheet\",\"href\":\"/_next/static/css/05190692196f8df0.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\",\"nonce\":\"$undefined\"}]],[\"$\",\"html\",null,{\"lang\":\"en\",\"className\":\"h-full\",\"children\":[[\"$\",\"head\",null,{\"children\":[[\"$\",\"$L2\",null,{\"async\":true,\"defer\":true,\"data-api\":\"$undefined\",\"data-domain\":\"llamacoder.io\",\"data-exclude\":\"$undefined\",\"src\":\"https://plausible.io/js/script.js\",\"integrity\":\"$undefined\",\"crossOrigin\":\"$undefined\"}],[\"$\",\"$L2\",null,{\"id\":\"next-plausible-init\",\"dangerouslySetInnerHTML\":{\"__html\":\"window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }\"},\"nonce\":\"$undefined\"}],\"$undefined\"]}],[\"$\",\"$L3\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L4\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":[[],[\"$\",\"body\",null,{\"className\":\"flex min-h-full flex-col bg-gray-100 text-gray-900 antialiased\",\"children\":[\"$\",\"div\",null,{\"className\":\"flex grow flex-col\",\"children\":[[\"$\",\"header\",null,{\"className\":\"relative mx-auto flex w-full shrink-0 items-center justify-center py-6\",\"children\":[[\"$\",\"$L5\",null,{\"href\":\"/\",\"children\":[\"$\",\"$L6\",null,{\"src\":{\"src\":\"/_next/static/media/logo.4a8eb9cb.png\",\"height\":87,\"width\":690,\"blurDataURL\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAABCAMAAADU3h9xAAAAFVBMVEVOZ6BYWHkNKFAlcf8fJSpLgvfP1OD82GPKAAAAB3RSTlMrFxMbMGJlaC3xswAAAAlwSFlzAAAhOAAAITgBRZYxYAAAABFJREFUeJxjYGVmYGFkY2ACAAByABaxADWNAAAAAElFTkSuQmCC\",\"blurWidth\":8,\"blurHeight\":1},\"alt\":\"\",\"quality\":100,\"className\":\"mx-auto h-9 object-contain\",\"priority\":true}]}],[\"$\",\"div\",null,{\"className\":\"absolute right-3\",\"children\":[\"$\",\"a\",null,{\"href\":\"https://github.com/nutlope/llamacoder\",\"target\":\"_blank\",\"className\":\"ml-auto hidden items-center gap-3 rounded-2xl bg-white px-6 py-2 shadow sm:flex\",\"children\":[[\"$\",\"svg\",null,{\"width\":16,\"height\":16,\"viewBox\":\"0 0 16 16\",\"fill\":\"none\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"className\":\"h-4 w-4\",\"children\":[\"$\",\"path\",null,{\"fillRule\":\"evenodd\",\"clipRule\":\"evenodd\",\"d\":\"M8 0C3.582 0 0 3.672 0 8.203c0 3.623 2.292 6.699 5.471 7.783.4.075.546-.178.546-.396 0-.194-.007-.71-.01-1.394-2.226.495-2.696-1.1-2.696-1.1-.363-.948-.888-1.2-.888-1.2-.726-.508.055-.499.055-.499.803.058 1.225.845 1.225.845.714 1.253 1.873.891 2.328.682.074-.53.28-.891.509-1.096-1.776-.207-3.644-.911-3.644-4.054 0-.895.312-1.628.823-2.201-.082-.208-.357-1.042.079-2.17 0 0 .672-.222 2.2.84A7.485 7.485 0 018 3.967c.68.003 1.364.094 2.003.276 1.527-1.062 2.198-.841 2.198-.841.437 1.129.161 1.963.08 2.17.512.574.822 1.307.822 2.202 0 3.15-1.871 3.844-3.653 4.048.288.253.543.753.543 1.519 0 1.095-.01 1.98-.01 2.25 0 .219.144.474.55.394a8.031 8.031 0 003.96-2.989A8.337 8.337 0 0016 8.203C16 3.672 12.418 0 8 0z\",\"fill\":\"currentColor\"}]}],[\"$\",\"span\",null,{\"children\":\"GitHub Repo\"}]]}]}]]}],[\"$\",\"div\",null,{\"className\":\"flex grow items-center justify-center\",\"children\":[\"$\",\"h2\",null,{\"className\":\"text-3xl\",\"children\":\"404 | Not Found\"}]}]]}]}]],\"forbidden\":\"$undefined\",\"unauthorized\":\"$undefined\"}]]}]]}],{\"children\":[\"share\",[\"$\",\"$1\",\"c\",{\"children\":[null,[\"$\",\"body\",null,{\"className\":\"flex h-full min-h-full flex-col items-center justify-center\",\"children\":[\"$\",\"$L3\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\",\"share\",\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L4\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"forbidden\":\"$undefined\",\"unauthorized\":\"$undefined\"}]}]]}],{\"children\":[\"v2\",[\"$\",\"$1\",\"c\",{\"children\":[null,[\"$\",\"$L3\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\",\"share\",\"children\",\"v2\",\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L4\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"forbidden\":\"$undefined\",\"unauthorized\":\"$undefined\"}]]}],{\"children\":[[\"messageId\",\"KdSoaXpRW_pDsD-9\",\"d\"],[\"$\",\"$1\",\"c\",{\"children\":[null,[\"$\",\"$L3\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\",\"share\",\"children\",\"v2\",\"children\",\"$0:f:0:1:2:children:2:children:2:children:0\",\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L4\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"forbidden\":\"$undefined\",\"unauthorized\":\"$undefined\"}]]}],{\"children\":[\"__PAGE__\",[\"$\",\"$1\",\"c\",{\"children\":[\"$L7\",null,[\"$\",\"$L8\",null,{\"children\":\"$L9\"}]]}],{},null,false]},[[\"$\",\"div\",\"l\",{\"className\":\"flex h-full flex-col items-center justify-center space-y-4\",\"children\":[[\"$\",\"$La\",null,{\"className\":\"block size-12\"}],[\"$\",\"p\",null,{\"children\":\"Loading your app...\"}]]}],[],[]],false]},null,false]},null,false]},null,false],[\"$\",\"$1\",\"h\",{\"children\":[null,[\"$\",\"$1\",\"OZvPmfYz7GTpYEDzUYoKF\",{\"children\":[[\"$\",\"$Lb\",null,{\"children\":\"$Lc\"}],[\"$\",\"$Ld\",null,{\"children\":\"$Le\"}],null]}]]}],false]],\"m\":\"$undefined\",\"G\":[\"$f\",\"$undefined\"],\"s\":false,\"S\":false}\n"])</script><script>self.__next_f.push([1,"e:[[\"$\",\"meta\",\"0\",{\"name\":\"viewport\",\"content\":\"width=device-width, initial-scale=1\"}]]\n"])</script><script>self.__next_f.push([1,"10:I[40854,[\"6079\",\"static/chunks/363642f4-fa7e3873b5bfa215.js\",\"4767\",\"static/chunks/c42d93a8-65985a8c59b3ceb7.js\",\"751\",\"static/chunks/751-87eadb259cd4fb14.js\",\"854\",\"static/chunks/854-73482541774c4e19.js\",\"8084\",\"static/chunks/app/share/v2/%5BmessageId%5D/page-4ea1f0875fffb3e3.js\"],\"default\"]\n11:Tc19,"])</script><script>self.__next_f.push([1,"import { useState } from 'react'\nimport { Button } from \"/components/ui/button\"\nimport { Card, CardContent, CardHeader, CardTitle } from \"/components/ui/card\"\nimport { Trash } from \"lucide-react\"\n\nexport default function ImageUploader() {\n const [images, setImages] = useState\u003cFile[]\u003e([])\n\n const handleFileChange = (event: React.ChangeEvent\u003cHTMLInputElement\u003e) =\u003e {\n const files = event.target.files\n if (files) {\n handleFiles(files)\n }\n }\n\n const handleDrop = (event: React.DragEvent\u003cHTMLDivElement\u003e) =\u003e {\n event.preventDefault()\n const files = event.dataTransfer.files\n handleFiles(files)\n }\n\n const handleFiles = (files: FileList) =\u003e {\n for (let i = 0; i \u003c files.length; i++) {\n const file = files[i]\n if (file.type.startsWith('image/') \u0026\u0026 file.size \u003c= 5 * 1024 * 1024) { // 5MB limit\n setImages(prevImages =\u003e [...prevImages, file])\n } else {\n alert(`File ${file.name} is not a valid image or exceeds 5MB limit.`)\n }\n }\n }\n\n const handleDeleteImage = (index: number) =\u003e {\n setImages(prevImages =\u003e prevImages.filter((_, i) =\u003e i !== index))\n }\n\n const handleDragOver = (event: React.DragEvent\u003cHTMLDivElement\u003e) =\u003e {\n event.preventDefault()\n }\n\n return (\n \u003cdiv className=\"p-4\"\u003e\n \u003cCard className=\"w-full max-w-4xl mx-auto\"\u003e\n \u003cCardHeader\u003e\n \u003cCardTitle className=\"text-2xl font-bold\"\u003eImage Uploader\u003c/CardTitle\u003e\n \u003c/CardHeader\u003e\n \u003cCardContent\u003e\n \u003cdiv\n className=\"mb-4 border-2 border-dashed border-gray-300 rounded-lg p-4 flex items-center justify-center text-center\"\n onDrop={handleDrop}\n onDragOver={handleDragOver}\n \u003e\n \u003cdiv\u003e\n \u003cp className=\"text-gray-500\"\u003eDrag \u0026 Drop images here\u003c/p\u003e\n \u003cp className=\"text-gray-500\"\u003eor\u003c/p\u003e\n \u003cButton variant=\"secondary\" asChild\u003e\n \u003clabel htmlFor=\"file-upload\" className=\"cursor-pointer\"\u003e\n Upload Images\n \u003c/label\u003e\n \u003c/Button\u003e\n \u003cinput\n id=\"file-upload\"\n type=\"file\"\n accept=\"image/*\"\n multiple\n onChange={handleFileChange}\n className=\"hidden\"\n /\u003e\n \u003c/div\u003e\n \u003c/div\u003e\n \u003cdiv className=\"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4\"\u003e\n {images.map((image, index) =\u003e (\n \u003cdiv key={index} className=\"relative\"\u003e\n \u003cimg\n src={URL.createObjectURL(image)}\n alt={`Uploaded ${index}`}\n className=\"w-full h-48 object-cover rounded-lg\"\n /\u003e\n \u003cButton\n variant=\"destructive\"\n size=\"icon\"\n className=\"absolute top-2 right-2\"\n onClick={() =\u003e handleDeleteImage(index)}\n \u003e\n \u003cTrash className=\"h-4 w-4\" /\u003e\n \u003c/Button\u003e\n \u003c/div\u003e\n ))}\n \u003c/div\u003e\n \u003c/CardContent\u003e\n \u003c/Card\u003e\n \u003c/div\u003e\n )\n}"])</script><script>self.__next_f.push([1,"7:[\"$\",\"div\",null,{\"className\":\"flex h-full w-full grow items-center justify-center\",\"children\":[\"$\",\"$L10\",null,{\"code\":\"$11\",\"onRequestFix\":\"$undefined\"}]}]\n"])</script><script>self.__next_f.push([1,"c:[[\"$\",\"meta\",\"0\",{\"charSet\":\"utf-8\"}],[\"$\",\"title\",\"1\",{\"children\":\"Image Upload Script\"}],[\"$\",\"meta\",\"2\",{\"name\":\"description\",\"content\":\"An app generated on LlamaCoder.io: Image Upload Script\"}],[\"$\",\"meta\",\"3\",{\"property\":\"og:title\",\"content\":\"Image Upload Script\"}],[\"$\",\"meta\",\"4\",{\"property\":\"og:description\",\"content\":\"An app generated on LlamaCoder.io: Image Upload Script\"}],[\"$\",\"meta\",\"5\",{\"property\":\"og:image\",\"content\":\"https://llamacoder.io/api/og?prompt=Image+Upload+Script\"}],[\"$\",\"meta\",\"6\",{\"name\":\"twitter:card\",\"content\":\"summary_large_image\"}],[\"$\",\"meta\",\"7\",{\"name\":\"twitter:title\",\"content\":\"Image Upload Script\"}],[\"$\",\"meta\",\"8\",{\"name\":\"twitter:description\",\"content\":\"An app generated on LlamaCoder.io: Image Upload Script\"}],[\"$\",\"meta\",\"9\",{\"name\":\"twitter:image\",\"content\":\"https://llamacoder.io/api/og?prompt=Image+Upload+Script\"}],[\"$\",\"link\",\"10\",{\"rel\":\"icon\",\"href\":\"/favicon.ico\",\"type\":\"image/x-icon\",\"sizes\":\"16x16\"}],[\"$\",\"link\",\"11\",{\"rel\":\"icon\",\"href\":\"/favicon.ico\"}]]\n9:null\n"])</script></body></html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Image Upload Drag & Drop</title>
|
| 7 |
+
<style>
|
| 8 |
+
body {
|
| 9 |
+
font-family: Arial, sans-serif;
|
| 10 |
+
text-align: center;
|
| 11 |
+
}
|
| 12 |
|
| 13 |
+
.drop-area {
|
| 14 |
+
width: 400px;
|
| 15 |
+
height: 200px;
|
| 16 |
+
margin: 50px auto;
|
| 17 |
+
border: 2px dashed #ccc;
|
| 18 |
+
display: flex;
|
| 19 |
+
justify-content: center;
|
| 20 |
+
align-items: center;
|
| 21 |
+
color: #aaa;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
.drop-area.dragover {
|
| 25 |
+
border-color: #000;
|
| 26 |
+
background-color: #f0f0f0;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
.drop-area img {
|
| 30 |
+
max-width: 100%;
|
| 31 |
+
max-height: 100%;
|
| 32 |
+
}
|
| 33 |
+
</style>
|
| 34 |
+
</head>
|
| 35 |
+
<body>
|
| 36 |
+
|
| 37 |
+
<h1>Drag & Drop Image Upload</h1>
|
| 38 |
+
<div class="drop-area">
|
| 39 |
+
Drag & Drop your image here or click to upload
|
| 40 |
+
</div>
|
| 41 |
+
|
| 42 |
+
<script>
|
| 43 |
+
const dropArea = document.querySelector('.drop-area');
|
| 44 |
+
|
| 45 |
+
// Prevent default drag behaviors
|
| 46 |
+
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
|
| 47 |
+
dropArea.addEventListener(eventName, preventDefaults, false);
|
| 48 |
+
});
|
| 49 |
+
|
| 50 |
+
function preventDefaults(e) {
|
| 51 |
+
e.preventDefault();
|
| 52 |
+
e.stopPropagation();
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
// Highlight drop area when item is dragged over it
|
| 56 |
+
['dragenter', 'dragover'].forEach(eventName => {
|
| 57 |
+
dropArea.addEventListener(eventName, () => dropArea.classList.add('dragover'), false);
|
| 58 |
+
});
|
| 59 |
+
|
| 60 |
+
['dragleave', 'drop'].forEach(eventName => {
|
| 61 |
+
dropArea.addEventListener(eventName, () => dropArea.classList.remove('dragover'), false);
|
| 62 |
+
});
|
| 63 |
+
|
| 64 |
+
// Handle dropped files
|
| 65 |
+
dropArea.addEventListener('drop', handleDrop, false);
|
| 66 |
+
|
| 67 |
+
function handleDrop(e) {
|
| 68 |
+
const dt = e.dataTransfer;
|
| 69 |
+
const files = dt.files;
|
| 70 |
+
|
| 71 |
+
handleFiles(files);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
function handleFiles(files) {
|
| 75 |
+
([...files]).forEach(uploadFile);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
function uploadFile(file) {
|
| 79 |
+
if (!file.type.startsWith('image/')) {
|
| 80 |
+
alert("This file is not an image.");
|
| 81 |
+
return;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
const reader = new FileReader();
|
| 85 |
+
|
| 86 |
+
reader.onload = function(e) {
|
| 87 |
+
const img = document.createElement('img');
|
| 88 |
+
img.src = e.target.result;
|
| 89 |
+
dropArea.innerHTML = '';
|
| 90 |
+
dropArea.appendChild(img);
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
+
reader.readAsDataURL(file);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
// Open file dialog on click
|
| 97 |
+
dropArea.addEventListener('click', () => {
|
| 98 |
+
const input = document.createElement('input');
|
| 99 |
+
input.type = 'file';
|
| 100 |
+
input.accept = 'image/*';
|
| 101 |
+
|
| 102 |
+
input.onchange = function(e) {
|
| 103 |
+
const files = e.target.files;
|
| 104 |
+
handleFiles(files);
|
| 105 |
+
};
|
| 106 |
+
|
| 107 |
+
input.click();
|
| 108 |
+
});
|
| 109 |
+
</script>
|
| 110 |
+
|
| 111 |
+
</body>
|
| 112 |
+
</html>
|