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

PHP 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.php', {
        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 $_POST['src'] variable. The FroalaEditor_Image::delete() method from the PHP SDK is expecting the path of the image to remove from disk.

Note: The path of the image is relative to the $_SERVER['DOCUMENT_ROOT'] global variable.

$response = FroalaEditor_Image::delete($_POST['src']);

Complete Example

<script>
    // Ask the server to delete an image file.
    function deleteImage (src) {
        fetch('/delete_image.php', {
        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>
<?php

// Include the editor SDK.
require 'PATH_TO_FROALA_SDK/lib/froala_editor.php';

// Delete the image.
try {
  $response = FroalaEditor_Image::delete($_POST['src']);
  echo stripslashes(json_encode('Success'));
} catch (Exception $e) {
  http_response_code(404);
}

?>

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