I want to override vendor/magento/module-page-builder/Controller/Adminhtml/ContentType/Image/Upload.php. please help me.
I want to allow webp extension in code using the override method.
You can follow these steps:
Create a new module or use an existing one to contain your customizations. For example, you can create a module called Vendor_Module.
In your module directory, create a new file called di.xml under Vendor/Module/etc/adminhtml/.
Add the following code to di.xml to override the Upload.php file:
<preference for="Magento\PageBuilder\Controller\Adminhtml\ContentType\Image\Upload" type="Vendor\Module\Controller\Adminhtml\ContentType\Image\Upload" />
Create a new file called Upload.php under Vendor/Module/Controller/Adminhtml/ContentType/Image/.
Copy the contents of vendor/magento/module-page-builder/Controller/Adminhtml/ContentType/Image/Upload.php into your new Upload.php file.
Modify the code in your Upload.php file to allow the webp extension. For example, you can add the following code to the isAllowedExtension method:
case 'webp':
return true;
This will allow the webp extension to be uploaded along with the other allowed extensions.
Once you have completed these steps, your custom Upload.php file will be used instead of the original file in Magento\PageBuilder\Controller\Adminhtml\ContentType\Image\Upload. The webp extension will now be allowed for image uploads.