I want every user need to upload the business registration document while registration. I have created the custom fields to upload the document, I can save the file name in database and it showing in customer grid also but how to save the uploaded document in our file-manager/server and how to access the file from admin(Customer Grid).
InstallData.php
<?php
namespace MyModules\CustomerUploadFile\Setup;
use Magento\Framework\Module\Setup\Migration;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
/**
* @codeCoverageIgnore
*/
class InstallData implements InstallDataInterface
{
protected $_logger;
/**
* Constructor
* @param \YourNamespace\YourModule\Logger\Logger $logger
*/
/**
* Customer setup factory
*
* @var \Magento\Customer\Setup\CustomerSetupFactory
*/
private $customerSetupFactory;
/**
* Init
*
* @param \Magento\Customer\Setup\CustomerSetupFactory $customerSetupFactory
*/
public function __construct(\Magento\Customer\Setup\CustomerSetupFactory $customerSetupFactory)
{
$this->customerSetupFactory = $customerSetupFactory;
}
/**
* Installs DB schema for a module
*
* @param ModuleDataSetupInterface $setup
* @param ModuleContextInterface $context
* @return void
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;
$installer->startSetup();
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
$entityTypeId = $customerSetup->getEntityTypeId(\Magento\Customer\Model\Customer::ENTITY);
$customerSetup->addAttribute(\Magento\Customer\Model\Customer::ENTITY, "business_registration_file", array(
"type" => "varchar",
"backend" => "",
"label" => "Business Registration Doc.",
"input" => "file",
"source" => '',
"visible" => true,
"required" => true,
"default" => "",
"frontend" => "",
"unique" => false,
"note" => "",
"is_used_in_grid" => true,
"is_visible_in_grid" => true,
"is_filterable_in_grid" => true,
"is_searchable_in_grid" => true
));
$regulation = $customerSetup->getEavConfig()->getAttribute(\Magento\Customer\Model\Customer::ENTITY, 'business_registration_file');
$used_in_forms[]="customer_account_edit";
$used_in_forms[]="customer_account_create";
$used_in_forms[]="adminhtml_customer";
$regulation->setData("used_in_forms", $used_in_forms)
->setData("is_used_for_customer_segment", true)
->setData("is_system", 0)
->setData("is_user_defined", 1)
->setData("is_visible", 1)
->setData("sort_order", 100);
$regulation->save();
$installer->endSetup();
}
}
?>
additionalinfocustomer.phtml
<fieldset class="fieldset create account" data-hasrequired="<?php /*@escapeNotVerified */ echo __('* Required Fields') ?>">
<div class="field upload_file required">
<label for="business_registration_file"><?php echo $this->__('Business Registration Doc.') ?><span class="required">*</span></label><br />
<div class="control">
<input type="file" name="business_registration_file" id="business_registration_file" title="<?php echo $this->__('Business Registration Doc.') ?>" class="required-entry input-file" />
</div>
</div>
</div>
</fieldset>
Can anyone guide me how to do the remaining part to save the document.