| Server IP : 62.171.151.215 / Your IP : 216.73.217.53 Web Server : nginx/1.18.0 System : Linux vmi3128365 5.15.0-176-generic #186-Ubuntu SMP Fri Mar 13 11:01:42 UTC 2026 x86_64 User : alex ( 1000) PHP Version : 8.4.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/raptorseduction.com/wp-content/plugins/featured-image-dragdrop/ |
Upload File : |
jQuery(document).ready(function ($) {
var dropzone = $("#featured-image-dropzone");
var fileInput = $("#featured-image-file-input");
var progressBar = $("#featured-image-progress-bar");
var progressWrap = $("#featured-image-progress-wrap");
var statusText = $("#featured-image-status");
// Clic sur la zone → ouvre le sélecteur de fichier
dropzone.on("click", function () {
fileInput.trigger("click");
});
// Sélection via explorateur de fichiers
fileInput.on("change", function () {
var file = this.files[0];
if (file) uploadFile(file);
});
// Drag & drop
dropzone.on("dragover dragenter", function (e) {
e.preventDefault();
dropzone.addClass("is-over");
});
dropzone.on("dragleave dragend", function () {
dropzone.removeClass("is-over");
});
dropzone.on("drop", function (e) {
e.preventDefault();
dropzone.removeClass("is-over");
var file = e.originalEvent.dataTransfer.files[0];
if (file) uploadFile(file);
});
function uploadFile(file) {
// Vérification type
if (!file.type.match(/^image\//)) {
setStatus("error", "Fichier non valide (image uniquement)");
return;
}
var formData = new FormData();
formData.append("action", "upload_featured_image");
formData.append("nonce", featuredImageUpload.nonce);
formData.append("post_id", featuredImageUpload.post_id);
formData.append("file", file);
setStatus("uploading", "Upload en cours…");
progressWrap.show();
progressBar.css("width", "0%");
$.ajax({
url: featuredImageUpload.ajax_url,
type: "POST",
data: formData,
contentType: false,
processData: false,
xhr: function () {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function (e) {
if (e.lengthComputable) {
var pct = Math.round((e.loaded / e.total) * 100);
progressBar.css("width", pct + "%");
}
});
return xhr;
},
success: function (response) {
progressBar.css("width", "100%");
if (response.success) {
setStatus("success", "✓ Image mise à jour !");
if (response.data && response.data.thumb_url) {
dropzone.css("background-image", "url(" + response.data.thumb_url + ")");
dropzone.addClass("has-preview");
}
setTimeout(function () {
progressWrap.fadeOut();
}, 1500);
} else {
setStatus("error", response.data.message || "Erreur inconnue");
progressWrap.hide();
}
},
error: function () {
setStatus("error", "Erreur réseau");
progressWrap.hide();
}
});
}
function setStatus(state, text) {
dropzone.removeClass("is-uploading is-success is-error").addClass("is-" + state);
statusText.text(text);
}
});