# searchpro/1.9.6/api/store_webp.php

BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS &amp; JavaScript, version 1.9.6. 21 lines.

- Page: https://pluginprobe.com/plugins/searchpro/1.9.6/code/api/store_webp.php
- Raw: https://pluginprobe.com/plugins/searchpro/1.9.6/raw/api/store_webp.php
- Modified: 2024-08-29T14:39:10+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/searchpro/1.9.6/code/api/store_webp.php#L10-L20`.

```php
<?php
if (!defined('ABSPATH'))
    exit;

$webp_img = base64_decode($request->get_param('image'));
$webp_url = sanitize_text_field($request->get_param('url'));
$webp_path = str_replace(get_site_url(), ABSPATH, $webp_url);

// Validate file extension
$valid_extensions = ['jpg', 'jpeg', 'png', 'webp', 'svg'];
$url_path = parse_url($webp_url, PHP_URL_PATH);
$file_extension = strtolower(pathinfo($url_path, PATHINFO_EXTENSION));

// Check the file extension
if (!in_array($file_extension, $valid_extensions)) {
    return false;
}

// Save the image to the specified path
$store = file_put_contents($webp_path, $webp_img);
unset($webp_img);
```
