Hi,
I am trying to change the MAX_IMAGE_WIDTH and MAX_IMAGE_HEIGHT values without changing the code in core, Does anyone know how I can override these values correctly? I have tried following some examples online but they haven't worked.
Thanks in advance!
Hello @dave_lynch1,
You have to just create one module inside app/code folder.
Inside etc/di.xml file
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Framework\File\Uploader" type="Vendor\Module\File\Uploader" /> </config>
Now just create one folder under Module, File and create Uploader.php file.
app/code/Vendor/Module/File Uploader.php file
<?php namespace Vendor\Module\File; use Magento\Framework\Filesystem\DriverInterface; class Uploader extends \Magento\Framework\File\Uploader { /** * Uploaded file handle (copy of $_FILES[] element) * * @var array * @access protected */ protected $_file; /** * Uploaded file mime type * * @var string * @access protected */ protected $_fileMimeType; /** * Upload type. Used to right handle $_FILES array. * * @var \Magento\Framework\File\Uploader::SINGLE_STYLE|\Magento\Framework\File\Uploader::MULTIPLE_STYLE * @access protected */ protected $_uploadType; /** * The name of uploaded file. By default it is original file name, but when * we will change file name, this variable will be changed too. * * @var string * @access protected */ protected $_uploadedFileName; /** * The name of destination directory * * @var string * @access protected */ protected $_uploadedFileDir; /** * If this variable is set to TRUE, our library will be able to automatically create * non-existent directories. * * @var bool * @access protected */ protected $_allowCreateFolders = true; /** * If this variable is set to TRUE, uploaded file name will be changed if some file with the same * name already exists in the destination directory (if enabled). * * @var bool * @access protected */ protected $_allowRenameFiles = false; /** * If this variable is set to TRUE, files dispertion will be supported. * * @var bool * @access protected */ protected $_enableFilesDispersion = false; /** * This variable is used both with $_enableFilesDispersion == true * It helps to avoid problems after migrating from case-insensitive file system to case-insensitive * (e.g. NTFS->ext or ext->NTFS) * * @var bool * @access protected */ protected $_caseInsensitiveFilenames = true; /** * @var string * @access protected */ protected $_dispretionPath = null; /** * @var bool */ protected $_fileExists = false; /** * @var null|string[] */ protected $_allowedExtensions = null; /** * Validate callbacks storage * * @var array * @access protected */ protected $_validateCallbacks = []; /**#@+ * File upload type (multiple or single) */ const SINGLE_STYLE = 0; const MULTIPLE_STYLE = 1; /**#@-*/ /** * Temp file name empty code */ const TMP_NAME_EMPTY = 666; /** * Max Image Width resolution in pixels. For image resizing on client side */ const MAX_IMAGE_WIDTH = 1920; /** * Max Image Height resolution in pixels. For image resizing on client side */ const MAX_IMAGE_HEIGHT = 1200; }
--
If my answer is useful, please Accept as Solution & give Kudos
Thanks for your response, I have tried implementing your solution but it hasn't worked :/
Thanks!
We should not override the constant variables of the class.
If having already a custom admin theme, you can override these templates in your custom admin theme.
I saw some templates which use these constant variables:
vendor/magento/module-backend/view/adminhtml/templates/media/uploader.phtml
vendor/magento/module-cms/view/adminhtml/templates/browser/content/uploader.phtml
Read more here: http://devdocs.magento.com/guides/v2.1/frontend-dev-guide/themes/admin_theme_create.html
Have you got a solution
Try placing file at following location -
lib/internal/Magento/Framework/File/Uploader
We can override using preference.
- Create di.xml
- Create class php file
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:frameworkbjectManager/etc/config.xsd">
<preference for="vendor\magento\framework\File\Uploader" type="NameSpace\Customer\Framework\File\Uploader" />
</config>
- In the given path put your fle `NameSpace\Customer\Framework\File\Uploader`