I'm trying to save some files after a form submission. Here's my function that currently saves the file(s):

  private function uploadFile($id) {
    $uploader = $this->_fileUploaderFactory->create(['fileId' => $id]);

    $path = $this->_fileSystem->getDirectoryRead(DirectoryList::MEDIA)

    $uploader->save($path . '/job/submissions');

    return '/job/submissions' . $uploader->getUploadedFileName();

This get's saved as I expect, but the files are accessible for every visitor. So my question is how or where can I save a file that can only be accessed by an admin?

  • Better you create Acl for admin in your custom module – aravind Jul 5 '19 at 9:03
  • It's not about Acl I think. The file comes from a frontend form an needs to be view-able for admin users only. – Arno Vande Cappelle Jul 5 '19 at 9:06
  • @ArnoVandeCappelle, you can use .htaccess to validate url, pass your username through URL and validate that user through .htaccess and give him the access, you can use that as your last option, give us more detail on how you are trying to access those URL's like through grid, or from any other resource. – Ashish Ranade Jul 15 '19 at 11:26

I fixed this issue by uploading the file to a non public path (/var for example). In the backoffice I created a link that creates a download for the file. I was hoping there was an easy way to access files only from the backoffice (media/adminhtml would be nice).

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.