2

I show this error in marketplace review

Namespace for Exception class is not specified.

Here is my code:

public function uploadFile($scope)
{   
   try {
        $uploader = $this->_fileUploaderFactory->create(['fileId' => $scope]);
        $uploader->setAllowRenameFiles(true);
        $uploader->setFilesDispersion(true);
        $uploader->setAllowCreateFolders(true);

        if ($uploader->save($this->getBaseDir())) {
            return $uploader->getUploadedFileName();    
        }

    } catch (Exception $e) {
        throw new $e('The file was not uploaded.', $code);
    }
    return '';
}

What is wrong with this?

6

Replace Exception $e to \Exception $e

Final Code

public function uploadFile($scope)
{   
   try {
        $uploader = $this->_fileUploaderFactory->create(['fileId' => $scope]);
        $uploader->setAllowRenameFiles(true);
        $uploader->setFilesDispersion(true);
        $uploader->setAllowCreateFolders(true);

        if ($uploader->save($this->getBaseDir())) {
            return $uploader->getUploadedFileName();    
        }

    } catch (\Exception $e) {
        throw new $e('The file was not uploaded.', $code);
    }
    return '';
}
  • Use of die language construct is discouraged. I am using header location in phtml, so using die – jafar pinjar Feb 8 at 8:08

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.