Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/app/code/Cnc/Catalog/Plugin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Cnc/Catalog/Plugin/UploaderPlugin.php
<?php
/**
 * Copyright (c) 2021 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved.
 * https://opensource.org/licenses/OSL-3.0  Open Software License (OSL 3.0)
 * Krzysztof Majkowski <[email protected]>
 */

namespace Cnc\Catalog\Plugin;

use Magento\Framework\File\Uploader;

class UploaderPlugin
{

    /**
     * @param \Magento\Framework\File\Uploader $subject
     * @param string[] $extensions
     * @return array
     */
    public function beforeSetAllowedExtensions(\Magento\Framework\File\Uploader $subject, $extensions = [])
    {
        if (!in_array('webp', $extensions)) {
            $extensions []= 'webp';
        }
        return [$extensions];
    }

    /**
     * @param \Magento\Framework\File\Uploader $subject
     * @param string[] $validTypes
     * @return array
     */
    public function beforeCheckMimeType(\Magento\Framework\File\Uploader $subject, $validTypes = [])
    {
        if ($this->isImageType($validTypes)) {
            $validTypes []= 'image/webp';
        }

        return [$validTypes];
    }

    /**
     * @param array $validTypes
     * @return bool
     */
    private function isImageType($validTypes = [])
    {
        $isImage = false;
        foreach ($validTypes as $type) {
            if (substr($type, 0, 5) == 'image') {
                $isImage = true;
                break;
            }
        }

        return $isImage;
    }
}

Spamworldpro Mini