jQuery(document).ready(function() { var input = document.querySelector('input[name="IMAGE"]'); input.type = 'hidden'; // Make the existing input hidden // Create a new input for image upload var imageInput = document.createElement('input'); imageInput.type = 'file'; imageInput.accept = 'image/jpeg, image/png, image/webp'; // Accept only images // Insert the new image input after the hidden input input.parentNode.insertBefore(imageInput, input.nextSibling); // Function to handle image file selection and conversion to base64 imageInput.addEventListener('change', function(event) { var file = event.target.files[0]; if (file) { var reader = new FileReader(); reader.onload = function(e) { var base64String = e.target.result; input.value = base64String; // Set the hidden input value to the base64 string var event = new Event('change', { bubbles: true }); input.dispatchEvent(event); }; reader.readAsDataURL(file); // Convert the image file to a base64 string } }); });
Sök
Stäng denna sökruta.

Hello world!

Welcome to WordPress. This is your first post. Edit or delete it, then start writing!