I have added a customer attribute called "My File". It gets added in customer account edit form. By default, the selected file(My File) is saved under "pub/media/customer" directory. In my case, I want to save those files alone under "pub/media/my_files". How to achieve it? Please help me!
Creating attributes in InstallData.php
use Magento\Customer\Setup\CustomerSetupFactory; use Magento\Customer\Model\Customer; use Magento\Eav\Model\Entity\Attribute\Set as AttributeSet; use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\App\ProductMetadataInterface; /** * @codeCoverageIgnore */ class InstallData implements InstallDataInterface { /** * Customer setup factory * * @var CustomerSetupFactory */ private $customerSetupFactory; /** * Customer Attribute setup factory * * @var AttributeSetFactory */ private $attributeSetFactory; /** * Customer Attribute setup factory * * @var ProductMetadataInterface */ private $productMetadataInterface; /** * Init * * @param CustomerSetupFactory $customerSetupFactory * @param AttributeSetFactory $attributeSetFactory * @param ProductMetadataInterface $productMetadataInterface */ public function __construct(CustomerSetupFactory $customerSetupFactory, AttributeSetFactory $attributeSetFactory, ProductMetadataInterface $productMetadataInterface) { $this->customerSetupFactory = $customerSetupFactory; $this->attributeSetFactory = $attributeSetFactory; $this->productMetadataInterface = $productMetadataInterface; } /** * {@inheritdoc} * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { /** @var CustomerSetup $customerSetup */ $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]); $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer'); $attributeSetId = $customerEntity->getDefaultAttributeSetId(); /** @var $attributeSet AttributeSet */ $attributeSet = $this->attributeSetFactory->create(); $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); $attributeList['my_file'] = [ 'type' => 'varchar', 'label' => 'My file', 'input' => 'file', 'required' => false, 'visible' => true, 'user_defined' => true, 'sort_order' => 150, 'position' => 150, 'system' => 0, 'validate_rules' => '{"max_file_size":1048576,"file_extensions":"pdf,jpg,png,jpeg,PDF,JPG,PNG,JPEG"}' ]; $attributeList['my_file_link'] = [ 'type' => 'varchar', 'label' => 'My File Link', 'input' => 'text', 'required' => false, 'visible' => true, 'user_defined' => true, 'sort_order' => 160, 'position' => 160, 'system' => 0 ]; foreach ($attributeList as $key => $value) { $customerSetup->addAttribute(Customer::ENTITY, $key, $value); //add attribute to attribute set $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, $key) ->addData( [ 'attribute_set_id' => $attributeSetId, 'attribute_group_id' => $attributeGroupId, 'used_in_forms' => ['customer_account_edit', 'checkout_register', 'adminhtml_customer'] ] ); $attribute->save(); } } }