如何在Magento 2中添加自定义文件上传功能 [英] How to add a custom file upload function in Magento 2

查看:15
本文介绍了如何在Magento 2中添加自定义文件上传功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过Magento 2类别选项卡中的一个定制模块创建了一些文件上传功能。我不知道如何将文件保存到数据库中。我该怎么做呢?

推荐答案

add use MagentoFrameworkUrlInterface;
add use MagentoFrameworkFilesystem;

...
$imageName = $this->uploadFileAndGetName('input_name', $this->fileSystem->getDirectoryWrite(DirectoryList::MEDIA)->getAbsolutePath($subdir_of_your_choice.'/image'));
$your_model->setImage($imageName);

这篇关于如何在Magento 2中添加自定义文件上传功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆