Does Anyone Know how can we get module file system path in magento 2 inside controller ?


Use code below to get module directory path

class CustomModel
     * @var \Magento\Framework\Module\Dir\Reader
    protected $moduleReader;

     * @param \Magento\Framework\Module\Dir\Reader $moduleReader
    public function __construct(
        \Magento\Framework\Module\Dir\Reader $moduleReader
    ) {
        $this->moduleReader = $moduleReader;

    public function getDirectory()
        $viewDir = $this->moduleReader->getModuleDir(
        return $viewDir . '/frontend/web/images'; //your file path

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.