I am getting this error when I submit the form from the front end. Although I set the required extension in the setAllowedExtensions

Exception #0 (InvalidArgumentException): Disallowed file type.

        foreach ($files as $key => $value) {

            $uploaderFactory = $this->uploaderFactory->create(['fileId' => $key]);
            $uploaderFactory->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png','pdf', 'docx', 'doc']);
            $imageAdapter = $this->adapterFactory->create();
            /* start of validated image */
            $mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
            $destinationPath = $mediaDirectory->getAbsolutePath('custom_module');
            $result = $uploaderFactory->save($destinationPath);

            $imagepath = $result['file'];

            $saveData['custom_file'] = $imagepath;


When I upload a jpeg or png it works fine ,but gives error on doc,docx and pdf

  • 1
    Comment out $uploaderFactory->addValidateCallback('custom_image_upload', $imageAdapter,'validateUploadFile'); – Vivek Kumar Apr 30 '18 at 12:07

The problem with following code


You are using the Image Adapter factory that will not allow you upload the files. You can use File Uploader instead.


You have to add this function to your class

private function validateUploadFile($filePath)
    // @todo
    // your custom validation code here

Please try below code

$uploaderFactory->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png','pdf', 'docx', 'doc'));

instead of

$uploaderFactory->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png','pdf', 'docx', 'doc']);

Hope this helps.

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.