I already sent the file from phtml to controller and in the controller, I need to save that file into a directory here are HTML and PHP code.
<form class="myformdynamic" onsubmit="return Validate()" method="post" action="<?php echo $this->getUrl('helloworld/index/result');?>" enctype="multipart/form-data">
<input type="file" id="profileAdd" name="profileAdd"><span class="s"id="sfile"></span>
<button type="submit" id="btnsave" class="action submit primary">
<span >Save</span>
</button>
</form>
Here is my code
Result.php
controller in another file,
<?php
namespace Inchoo\Helloworld\Controller\Index;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
class Result extends Action
{
public function execute()
{
$fileName=['profileAdd']['name'];
echo $fileName;
//name of the file is printed which i uploaded from form
}
}