| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) |
| 3 |
exit; |
| 4 |
|
| 5 |
$webp_img = base64_decode($request->get_param('image')); |
| 6 |
$webp_url = sanitize_text_field($request->get_param('url')); |
| 7 |
$webp_path = str_replace(get_site_url(), ABSPATH, $webp_url); |
| 8 |
|
| 9 |
// Validate file extension |
| 10 |
$valid_extensions = ['jpg', 'jpeg', 'png', 'webp', 'svg']; |
| 11 |
$url_path = parse_url($webp_url, PHP_URL_PATH); |
| 12 |
$file_extension = strtolower(pathinfo($url_path, PATHINFO_EXTENSION)); |
| 13 |
|
| 14 |
// Check the file extension |
| 15 |
if (!in_array($file_extension, $valid_extensions)) { |
| 16 |
return false; |
| 17 |
} |
| 18 |
|
| 19 |
// Save the image to the specified path |
| 20 |
$store = file_put_contents($webp_path, $webp_img); |
| 21 |
unset($webp_img); |