0

I create Installdata.php

<?php /** * Copyright © 2018 Magento. All rights reserved. * See COPYING.txt for license details. */ namespace CP\Register\Setup; use Magento\Customer\Setup\CustomerSetupFactory; use Magento\Customer\Model\Customer; use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; /** * Install data * @codeCoverageIgnore */ class InstallData implements InstallDataInterface { /** * CustomerSetupFactory * @var CustomerSetupFactory */ protected $customerSetupFactory; /** * $attributeSetFactory * @var AttributeSetFactory */ private $attributeSetFactory; /** * initiate object * @param CustomerSetupFactory $customerSetupFactory * @param AttributeSetFactory $attributeSetFactory */ public function __construct( CustomerSetupFactory $customerSetupFactory, AttributeSetFactory $attributeSetFactory ) { $this->customerSetupFactory = $customerSetupFactory; $this->attributeSetFactory = $attributeSetFactory; } /** * install data method * @param ModuleDataSetupInterface $setup * @param ModuleContextInterface $context */ 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); /** * customer registration form default field mobile number */ $customerSetup->addAttribute(Customer::ENTITY, 'documents', [ 'type' => 'varchar', 'label' => 'ID Documents', 'input' => 'file', 'required' => true, 'visible' => true, 'user_defined' => false, 'sort_order' => 1000, 'position' => 1000, 'system' => 0, ]); //add attribute to attribute set $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'documents') ->addData([ 'attribute_set_id' => $attributeSetId, 'attribute_group_id' => $attributeGroupId, 'used_in_forms' => ['adminhtml_customer', 'customer_account_create', 'customer_address_edit', 'customer_register_address', 'checkout_register', 'adminhtml_checkout'], ]); $attribute->save(); } } 

After that in edit.phtml file i write code for that

<fieldset class="fieldset create account"> <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Additional Information') ?></span></legend> <p> <div class="fileadd"> <label for="FileAdd" class="label"> <span><?php /* @escapeNotVerified */ echo __('Id Document') ?></span> </label> <div class="control"> <input type="file" name="documents" id="documents" value="<?php echo $mediaPath."customer/".$block->escapeHtml($block->getCustomer()->getCustomAttribute('documents')->getValue()); ?>"" title="<?php /* @escapeNotVerified */ echo __('ID Document') ?>"><?php //echo $block->escapeHtml($block->getCustomer()->getCustomAttribute('documents')->getValue());?></input> <!-- <?php //echo $block->escapeHtml($block->getCustomer()->getCustomAttribute('documents')->getValue()) ?> --> </div> </div> </p> </fieldset> 

Now i want to get value here but i don't get

enter image description here

I want to like show this in account edit information

enter image description here

1 Answer 1

0

You can use a simple anchor tag.

<?php $customerMedia = $block->getBaseUrl() . 'pub/media/customer'; $customer_attribute_value = $customer->getData('customer_attribute_code'); $filePath = $customerMedia . $customer_attribute_value; ?> <?php if ($customer_attribute_value) : ?> <a href="<?php echo $filePath ?>">Your Document</a> <?php endif; ?> 

Note: If your file type is image only, you can use <img src='' />. If you have different file type such as pdf, then you can show a sample document icon and put it in an anchor tag.

3
  • no you don't get my question here i give link of image i want to like as prnt.sc/j1mq66 Commented Apr 6, 2018 at 8:49
  • You have to create custom preview section for this. I have added a note to the answer. You can read that. Commented Apr 6, 2018 at 8:56
  • @DineshYadav If I upload a file like this, abcd.pdf , then it creates folder like this - /pub/media/customer/a/b/ then how can i get pdf path Commented Jun 3, 2019 at 12:27

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.