AvocadoAmber/AvocadoEdition_Light/plugin/editor/cheditor5/imageUpload/delete.php

52 lines
1.3 KiB
PHP
Raw Normal View History

2022-09-17 20:50:50 +09:00
<?php
2024-09-28 13:03:15 +09:00
require_once "config.php";
2022-09-17 20:50:50 +09:00
2024-09-28 13:03:15 +09:00
if (!function_exists('ft_nonce_is_valid')) {
include_once "../editor.lib.php";
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:37:21 +09:00
$filesrc = isset($_POST["filesrc"]) ? preg_replace("/[ #\&\+\-%@=\/\\\:;,\'\"\^`~|\!\?\*$#<>()\[\]\{\}]/", "", $_POST["filesrc"]) : '';
2022-09-17 20:50:50 +09:00
2024-09-28 13:03:15 +09:00
if (!$filesrc || !preg_match('=^[^/?*;:{}\\\\]+\.[^/?*;:{}\\\\]+$=', $filesrc) || !preg_match('/\.(gif|jpe?g|bmp|png)$/i', $filesrc)) {
die(false);
2022-09-17 20:50:50 +09:00
}
$is_editor_upload = false;
2024-09-28 13:03:15 +09:00
$get_nonce = get_session('nonce_' . FT_NONCE_SESSION_KEY);
2022-09-17 20:50:50 +09:00
2024-09-28 13:03:15 +09:00
if ($get_nonce && ft_nonce_is_valid($get_nonce, 'cheditor')) {
$is_editor_upload = true;
2022-09-17 20:50:50 +09:00
}
2024-09-28 13:03:15 +09:00
if (!$is_editor_upload) {
die(false);
2022-09-17 20:50:50 +09:00
}
// ---------------------------------------------------------------------------
2024-09-28 13:03:15 +09:00
$file_arr = explode('_', $filesrc);
2022-09-17 20:50:50 +09:00
2024-09-28 13:03:15 +09:00
if ($file_arr[1] !== che_get_file_passname()) {
die(false);
2022-09-17 20:50:50 +09:00
}
$filepath = SAVE_DIR . '/' . $filesrc;
$r = false;
2024-09-28 13:03:15 +09:00
if (class_exists('EventHandler') && method_exists('EventHandler', 'triggerEvent')) {
EventHandler::triggerEvent("gnuboard.delete_editor_file", $filepath, $r);
2024-09-19 20:37:21 +09:00
}
2022-09-17 20:50:50 +09:00
if (file_exists($filepath)) {
2024-09-28 13:03:15 +09:00
$r = unlink($filepath);
if ($r) {
$thumbPath = dirname($filepath) . DIRECTORY_SEPARATOR . "thumb_" . basename($filepath);
if (file_exists($thumbPath)) {
unlink($thumbPath);
}
}
2022-09-17 20:50:50 +09:00
}
2024-09-26 08:55:13 +09:00
echo $r ? true : false;