Guest User

Untitled

a guest
Nov 20th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. ....
  2.  
  3. protected function getDataUploadField()
  4. {
  5. return [
  6. 'arguments' => [
  7. 'data' => [
  8. 'config' => [
  9. 'componentType' => 'fileUploader',
  10. 'formElement' => 'fileUploader',
  11. 'component' => 'Magento_Ui/js/form/element/file-uploader',
  12. 'dataScope' => 'file',
  13. 'fileInputName' => 'image',
  14. 'uploaderConfig' => [
  15. 'url' => $this->urlBuilder->addSessionParam()->getUrl(
  16. 'adminhtml/attachements_file/upload'
  17. ),
  18. ],
  19. ],
  20. ],
  21. ]
  22. ];
  23. }
  24.  
  25. ....
  26.  
  27. <?php
  28.  
  29. namespace VendorModuleControllerAdminhtmlAttachements;
  30.  
  31. abstract class File extends MagentoBackendAppAction
  32. {
  33.  
  34. const ADMIN_RESOURCE = 'Magento_Catalog::products';
  35. }
  36.  
  37. <?php
  38.  
  39. namespace VendorModuleControllerAdminhtmlAttachementsFile;
  40.  
  41. use MagentoBackendAppAction;
  42. use MagentoFrameworkAppFilesystemDirectoryList;
  43.  
  44. class Upload extends VendorModuleControllerAdminhtmlAttachementsFile
  45. {
  46. protected $UploaderFactory;
  47.  
  48. public function __construct(
  49. MagentoMediaStorageModelFileUploaderFactory $UploaderFactory,
  50. ActionContext $context
  51.  
  52. ) {
  53.  
  54. $this->UploaderFactory = $UploaderFactory;
  55. parent::__construct($context);
  56. }
  57.  
  58. public function execute(){
  59.  
  60. $uploader = $this->UploaderFactory->create(['fileId' => 'image']); //ERROR
  61.  
  62. $uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']);
  63.  
  64. $uploader->setAllowRenameFiles(false);
  65.  
  66. $uploader->setFilesDispersion(false);
  67.  
  68. $path = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)
  69. ->getAbsolutePath('images/');
  70.  
  71. $uploader->save($path);
  72.  
  73. }
  74. }
Add Comment
Please, Sign In to add comment