




{"id":12879,"date":"2025-05-16T12:33:24","date_gmt":"2025-05-16T11:33:24","guid":{"rendered":"https:\/\/www.tera-sat.com\/?page_id=12879"},"modified":"2025-05-18T10:23:08","modified_gmt":"2025-05-18T09:23:08","slug":"file-upload","status":"publish","type":"page","link":"https:\/\/www.tera-sat.com\/?page_id=12879","title":{"rendered":"File upload"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>File Upload Instructions<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To ensure the highest quality and smooth processing of your files, please carefully follow the guidelines below before uploading:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>File Format<\/strong><br>Only <strong>JPG (.jpg)<\/strong> files are accepted. Please ensure your files are saved in this format before uploading.<\/li>\n\n\n\n<li><strong>Image Specifications<\/strong><br>For best print quality, each image should be sized at <strong>2500 pixels on the long edge<\/strong> and have a resolution of <strong>300 DPI (dots per inch)<\/strong>. This ensures sharp, high-quality results in print.<\/li>\n\n\n\n<li><strong>File Naming<\/strong><br>Please <strong>rename your files<\/strong> clearly and consistently so they are easy to recognize. We recommend a format such as:<br><code>FirstName_LastName_ProjectTitle.jpg<\/code><br>Avoid generic names like <em>IMG_1234.jpg<\/em>.<\/li>\n\n\n\n<li><strong>Email Confirmation<\/strong><br>After uploading your files, please use the <a href=\"https:\/\/www.tera-sat.com\/?page_id=850\">contact form<\/a> to send me a message including a list of the <strong>exact filenames<\/strong> submitted. This helps us verify and organize your materials efficiently.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Adhering to these guidelines ensures your files are processed correctly and maintains the integrity of your work throughout our workflow.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you for your cooperation.<\/p>\n\n\n\n    <form id=\"uploadForm\" method=\"post\" enctype=\"multipart\/form-data\" style=\"margin-bottom:20px;\">\n        <input type=\"hidden\" id=\"_wpnonce\" name=\"_wpnonce\" value=\"064ae553ed\" \/><input type=\"hidden\" name=\"_wp_http_referer\" value=\"\/index.php?rest_route=%2Fwp%2Fv2%2Fpages%2F12879\" \/>        <div id=\"dropArea\" style=\"padding:40px; border:2px dashed #ccc; text-align:center; cursor:pointer; margin-bottom:10px;\">\n            Drag & drop JPG files here or click to select\n            <input type=\"file\" id=\"fileInput\" name=\"files[]\" accept=\".jpg,.jpeg\" multiple style=\"display:none;\">\n        <\/div>\n        <div id=\"fileList\" style=\"margin-bottom:10px;\"><\/div>\n        <button type=\"submit\" style=\" background: #f0f0f0; color: #333; padding: 8px 16px; border: none; border-radius: 6px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); cursor: pointer; margin: 5px;\">Upload Files<\/button>\n    <\/form>\n    <div id=\"uploadedThumbsContainer\"><\/div>\n\n       <script>\n    (function(){\n        const dropArea = document.getElementById('dropArea');\n        const fileInput = document.getElementById('fileInput');\n        const fileList = document.getElementById('fileList');\n        const uploadForm = document.getElementById('uploadForm');\n        const thumbsContainer = document.getElementById('uploadedThumbsContainer');\n        let filesArray = [];\n\n        dropArea.addEventListener('click', () => fileInput.click());\n        dropArea.addEventListener('dragover', e => { e.preventDefault(); dropArea.style.borderColor = '#333'; });\n        dropArea.addEventListener('dragleave', e => { e.preventDefault(); dropArea.style.borderColor = '#ccc'; });\n        dropArea.addEventListener('drop', e => { e.preventDefault(); dropArea.style.borderColor = '#ccc'; addFiles(e.dataTransfer.files); });\n        fileInput.addEventListener('change', e => { addFiles(e.target.files); });\n\n        function addFiles(newFiles) {\n            for(let i=0; i<newFiles.length; i++) {\n                const file = newFiles[i];\n                if(!file.name.match(\/\\.(jpg|jpeg)$\/i)) {\n                    alert(file.name + ' is not a JPG file.');\n                    continue;\n                }\n                filesArray.push(file);\n            }\n            updateFileList();\n        }\n\n        function updateFileList() {\n            fileList.innerHTML = '';\n            filesArray.forEach((file, index) => {\n                const div = document.createElement('div');\n                div.style.marginBottom = '6px';\n                const span = document.createElement('span');\n                span.textContent = file.name;\n                const btn = document.createElement('button');\n                btn.textContent = '\u274c';\n                btn.type = 'button';\n                btn.style.marginLeft = '10px';\n                btn.onclick = () => { filesArray.splice(index, 1); updateFileList(); };\n                div.appendChild(span);\n                div.appendChild(btn);\n                fileList.appendChild(div);\n            });\n            const dataTransfer = new DataTransfer();\n            filesArray.forEach(file => dataTransfer.items.add(file));\n            fileInput.files = dataTransfer.files;\n        }\n\n        uploadForm.addEventListener('submit', function(e){\n            if (filesArray.length === 0) return;\n            e.preventDefault();\n            const formData = new FormData(uploadForm);\n            filesArray.forEach(file => formData.append('files[]', file));\n            formData.append('action', 'custom_ajax_upload_files');\n            formData.append('_wpnonce', uploadForm.querySelector('input[name=\"_wpnonce\"]').value);\n            fetch('https:\/\/www.tera-sat.com\/wp-admin\/admin-ajax.php', {\n                method: 'POST', body: formData\n            })\n            .then(res => res.json())\n            .then(data => {\n                if (data.success) {\n                    filesArray = [];\n                    updateFileList();\n                    loadThumbnails();\n                } else {\n                    alert('Error: ' + data.data);\n                }\n            });\n        });\n\n        function loadThumbnails() {\n            fetch('https:\/\/www.tera-sat.com\/wp-admin\/admin-ajax.php?action=custom_list_uploaded_files')\n                .then(res => res.text())\n                .then(html => {\n                    thumbsContainer.innerHTML = html;\n                    bindDeleteButtons();\n                    bindRenameButtons();\n                });\n        }\n\n        function bindDeleteButtons() {\n            thumbsContainer.querySelectorAll('.delete-thumb').forEach(button => {\n                button.addEventListener('click', function (e) {\n                    const container = e.target.closest('.thumb');\n                    const fileUrl = container.getAttribute('data-url');\n                    if (!confirm('Delete this file?')) return;\n                    fetch('https:\/\/www.tera-sat.com\/wp-admin\/admin-ajax.php', {\n                        method: 'POST',\n                        headers: { 'Content-Type': 'application\/x-www-form-urlencoded' },\n                        body: new URLSearchParams({\n                            action: 'custom_delete_uploaded_file', file: fileUrl\n                        })\n                    })\n                    .then(res => res.json())\n                    .then(data => {\n                        if (data.success) loadThumbnails();\n                        else alert('Error: ' + data.data);\n                    });\n                });\n            });\n\n            const clearBtn = thumbsContainer.querySelector('#clearAllBtn');\n            if (clearBtn) {\n                clearBtn.addEventListener('click', function () {\n                    if (!confirm('Are you sure you want to delete all uploaded files?')) return;\n                    fetch('https:\/\/www.tera-sat.com\/wp-admin\/admin-ajax.php', {\n                        method: 'POST',\n                        headers: { 'Content-Type': 'application\/x-www-form-urlencoded' },\n                        body: new URLSearchParams({ action: 'custom_clear_all_uploads' })\n                    })\n                    .then(res => res.json())\n                    .then(data => {\n                        if (data.success) loadThumbnails();\n                        else alert('Error: ' + data.data);\n                    });\n                });\n            }\n        }\n\n        function bindRenameButtons() {\n            thumbsContainer.querySelectorAll('.rename-thumb').forEach(button => {\n                button.addEventListener('click', function (e) {\n                    const container = e.target.closest('.thumb');\n                    const fileUrl = container.getAttribute('data-url');\n                    let currentName = container.getAttribute('data-filename');\n\n                    \/\/ Split name and extension\n                    let dotIdx = currentName.lastIndexOf(\".\");\n                    let basename = dotIdx !== -1 ? currentName.substring(0, dotIdx) : currentName;\n                    let ext = dotIdx !== -1 ? currentName.substring(dotIdx) : \"\";\n\n                    \/\/ Create prompt with input and highlight only basename\n                    let input = document.createElement('input');\n                    input.type = 'text';\n                    input.value = basename + ext;\n                    input.style.width = '90%';\n\n                    \/\/ Show prompt in a modal-like dialog\n                    let modal = document.createElement('div');\n                    modal.style.position = 'fixed';\n                    modal.style.left = 0;\n                    modal.style.top = 0;\n                    modal.style.width = '100vw';\n                    modal.style.height = '100vh';\n                    modal.style.background = 'rgba(0,0,0,0.3)';\n                    modal.style.zIndex = 10000;\n                    modal.style.display = 'flex';\n                    modal.style.alignItems = 'center';\n                    modal.style.justifyContent = 'center';\n\n                    let box = document.createElement('div');\n                    box.style.background = '#fff';\n                    box.style.padding = '24px 16px 12px 16px';\n                    box.style.borderRadius = '8px';\n                    box.style.boxShadow = '0 2px 18px rgba(0,0,0,0.2)';\n                    box.style.textAlign = 'center';\n                    box.innerHTML = '<div style=\"margin-bottom:8px;font-weight:bold\">Rename file<\/div>';\n\n                    box.appendChild(input);\n\n                    let ok = document.createElement('button');\n                    ok.textContent = \"Rename\";\n                    ok.style.margin = '12px 8px 0 0';\n                    let cancel = document.createElement('button');\n                    cancel.textContent = \"Cancel\";\n                    cancel.style.margin = '12px 0 0 8px';\n\n                    box.appendChild(ok);\n                    box.appendChild(cancel);\n                    modal.appendChild(box);\n                    document.body.appendChild(modal);\n\n                    \/\/ Select only the basename (not the extension)\n                    setTimeout(() => {\n                        input.setSelectionRange(0, basename.length);\n                        input.focus();\n                    }, 100);\n\n                    ok.onclick = function() {\n                        let val = input.value.trim();\n                        if (!val || val === currentName) {\n                            document.body.removeChild(modal);\n                            return;\n                        }\n                        fetch('https:\/\/www.tera-sat.com\/wp-admin\/admin-ajax.php', {\n                            method: 'POST',\n                            headers: { 'Content-Type': 'application\/x-www-form-urlencoded' },\n                            body: new URLSearchParams({\n                                action: 'custom_rename_uploaded_file',\n                                file: fileUrl,\n                                newname: val\n                            })\n                        })\n                        .then(res => res.json())\n                        .then(data => {\n                            document.body.removeChild(modal);\n                            if (data.success) loadThumbnails();\n                            else alert('Error: ' + data.data);\n                        });\n                    };\n                    cancel.onclick = function() {\n                        document.body.removeChild(modal);\n                    };\n                    input.onkeydown = function(ev) {\n                        if (ev.key === \"Enter\") ok.onclick();\n                        if (ev.key === \"Escape\") cancel.onclick();\n                    }\n                });\n            });\n        }\n\n        document.addEventListener('DOMContentLoaded', loadThumbnails);\n    })();\n    <\/script>\n\n    \n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>File Upload Instructions To ensure the highest quality and smooth processing of your files, please carefully follow the guidelines below before uploading: Adhering to these guidelines ensures your files are processed correctly and maintains the integrity of your work throughout our workflow. Thank you for your cooperation.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-12879","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.tera-sat.com\/index.php?rest_route=\/wp\/v2\/pages\/12879","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tera-sat.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.tera-sat.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.tera-sat.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tera-sat.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12879"}],"version-history":[{"count":7,"href":"https:\/\/www.tera-sat.com\/index.php?rest_route=\/wp\/v2\/pages\/12879\/revisions"}],"predecessor-version":[{"id":12894,"href":"https:\/\/www.tera-sat.com\/index.php?rest_route=\/wp\/v2\/pages\/12879\/revisions\/12894"}],"wp:attachment":[{"href":"https:\/\/www.tera-sat.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12879"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}