We are aware of the recently disclosed PHP2Shell vulnerabilities (CVE-2026-109618 and CVE-2026-109619) and can confirm FROALA is not impacted by these vulnerabilities.

0
Days
00
Hours
00
Minutes
00
Seconds
x
Skip to content
Froala Documentation

Python Image Server Delete

How it works

  1. Code intercepts the image removed or replaced in the editor.
  2. Removing an image sends to the server a request to delete the image from disk.
  3. Once the request reaches the server, it deletes the image.

Jump to Complete Example

Intercept image being removed

Removing an image from the editor triggers two events: image.beforeRemove and image.removed. You can use either of them to delete the image from the server, however it is recommended to use the second one, since at that point you make sure that the image was removed from the editable area.

Replacing an image triggers image.replaced. Starting with v5.5, it passes the previous image's src as a third argument, old_src, so you can delete the replaced file the same way.

Send request to the server

There is no built-in feature that makes the request to the server, however you can use an AJAX request.

<script>
    // Ask the server to delete an image file.
    function deleteImage (src) {
        fetch('/delete_image', {
        method: 'POST',
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        body: new URLSearchParams({ src: src })
        })
        .then(function (response) {
        console.log(response.ok ? 'Image was deleted' : 'Image delete problem');
        })
        .catch(function (err) {
        console.log('Image delete problem: ' + err);
        });
    }

    new FroalaEditor('.selector', {
        events: {
        // An image was removed from the editor.
        'image.removed': function ($img) {
            deleteImage($img.attr('src'));
        },

        // An image was replaced. old_src is the image that was replaced (v5.5+).
        'image.replaced': function ($img, response, old_src) {
            deleteImage(old_src);
        }
        }
    });
    </script>

Delete the image

The server implementation is responsible for receiving the request and handling it appropriately. The code on the previous step makes the image path available in the body of the request. The Image.delete method from the Python SDK expects the path of the image to remove from disk.

Note: The path of the image is relative to the root of your application.

Image.delete(src)

Complete Example

<script>
    // Ask the server to delete an image file.
    function deleteImage (src) {
        fetch('/delete_image', {
        method: 'POST',
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        body: new URLSearchParams({ src: src })
        })
        .then(function (response) {
        console.log(response.ok ? 'Image was deleted' : 'Image delete problem');
        })
        .catch(function (err) {
        console.log('Image delete problem: ' + err);
        });
    }

    new FroalaEditor('.selector', {
        events: {
        // An image was removed from the editor.
        'image.removed': function ($img) {
            deleteImage($img.attr('src'));
        },

        // An image was replaced. old_src is the image that was replaced (v5.5+).
        'image.replaced': function ($img, response, old_src) {
            deleteImage(old_src);
        }
        }
    });
    </script>
# Django
from django.http import HttpResponse
import json
from froala_editor import Image

def delete_image(request):
    src = request.POST.get('src', '')
    try:
        Image.delete(src)
        return HttpResponse('ok', content_type="application/json")
    except:
        raise Exception('Could not delete image')
# Flask
from flask import request
import json
from froala_editor import Image

@app.route('/delete_image', methods=['POST'])
def delete_file():
    src = request.form.get('src')
    try:
        Image.delete(src)
        return json.dumps('ok')
    except:
        raise Exception('Could not delete file')
# Pyramid
from pyramid.response import Response
import json
from froala_editor import Image

def delete_image(request):
    src = request.POST.get('src')
    try:
        Image.delete(src)
        return Response(json.dumps('ok'))
    except:
        raise Exception('Could not delete image')

Do you think we can improve this article? Let us know.