Upload images through own Controller
Posted: 07 Jul 2015, 12:35
Hello, and sorry to bother you once again!
I'm trying to upload images through my own controller and my custom admin, so far I'm not having luck with getting the images uploaded. I found a _createItem() function, but I don't think I can access this through my custom Controller.
here's a bit of code:
Could you maybe point me in the right direction?
Thanks a lot!
I'm trying to upload images through my own controller and my custom admin, so far I'm not having luck with getting the images uploaded. I found a _createItem() function, but I don't think I can access this through my custom Controller.
here's a bit of code:
Code: Select all
$mediaManager = \MShop_Factory::createManager($context, 'media');
$mediaItem = $mediaManager->createItem(array());
$img = $request->file('image');
$mediaItem->setTypeId(1); //Product Type
$mediaItem->setDomain('product');
$mediaItem->setUrl($img);
$mediaItem->setPreview($img);
$mediaItem->setStatus($request->get('status'));
$mediaItem->setMimeType($img->getMimeType());
$mediaManager->saveItem($mediaItem, true);
Thanks a lot!