مهدی نوری زادگان
3 سال پیش توسط مهدی نوری زادگان مطرح شد
0 پاسخ

آپلود عکس در tiny mce

سلام دوستان.
من از tiny mce برای آپلود عکس استفاده کردم.

tinymce.init({
            selector: 'textarea#tiny',
            directionality: 'rtl',
            plugins: ["link", "code", "table", "media", "image", "textcolor", "emoticons", 'image code'],
            automatic_uploads: true,
            paste_data_images: true,
            file_picker_types: 'image',
            images_upload_url: 'upload.php',
            plugins: 'preview link image  code table emoticons textcolor numberlist codesample lists media lists advlist directionality',

            // override default upload handler to simulate successful upload
            images_upload_handler: function(blobInfo, success, failure) {
                var xhr, formData;

                xhr = new XMLHttpRequest();
                xhr.withCredentials = false;
                xhr.open('POST', 'upload.php');

                xhr.onload = function() {
                    var json;

                    if (xhr.status != 200) {
                        failure('HTTP Error: ' + xhr.status);
                        return;
                    }

                    json = JSON.parse(xhr.responseText);

                    if (!json || typeof json.location != 'string') {
                        failure('Invalid JSON: ' + xhr.responseText);
                        return;
                    }

                    success(json.location);
                };

                formData = new FormData();
                formData.append('file', blobInfo.blob(), blobInfo.filename());

                xhr.send(formData);
            }
        });

کد بالا مربوط هست به جاوااسکریپتم عکس در به لطف php درست آپلود میشه در پوشه درست ولی توی فضای ادیتور عکس نمایش داده نمیشه و ارور زیر رو میده:
Cannot read properties of undefined (reading 'then')
خیلی ممنون میشم اسکریپ درست رو به من بگید