Filesystems 如何从magento 2中的文件夹和子文件夹获取所有文件
我制作了一个在前端上传图像的模块。Magento 2以特殊方式保存文件。例如:Filesystems 如何从magento 2中的文件夹和子文件夹获取所有文件,filesystems,magento2,getfiles,Filesystems,Magento2,Getfiles,我制作了一个在前端上传图像的模块。Magento 2以特殊方式保存文件。例如: 上传文件-file.png 文件路径-pub/media/[module_folder]/f/i/file.png 如何从[module_folder]获取所有文件 尝试以下操作,使用directorylist类获取路径,使用file类读取目录:D public function __construct( \Magento\Framework\Filesystem\DirectoryList $dire
- 上传文件-
file.png
- 文件路径-
pub/media/[module_folder]/f/i/file.png
[module_folder]
获取所有文件
尝试以下操作,使用directorylist类获取路径,使用file类读取目录:D
public function __construct(
\Magento\Framework\Filesystem\DirectoryList $directoryList,
\Magento\Framework\Filesystem\Driver\File $driverFile,
LoggerInterface $logger)
{
$this->directoryList =$directoryList;
$this->driverFile = $driverFile;
$this->logger = $logger;
}
public function getAllFiles($path = '/import/') {
$paths = [];
try {
//get the base folder path you want to scan (replace var with pub / media or any other core folder)
$path = $this->directoryList->getPath('var') . $path;
//read just that single directory
$paths = $this->driverFile->readDirectory($path);
//read all folders
$paths = $this->driverFile->readDirectoryRecursively($path);
} catch (FileSystemException $e) {
$this->logger->error($e->getMessage());
}
return $paths;
}
如何得到它们?用什么系统/语言?什么格式?我想获取文件夹和子文件夹中所有文件的名称和路径。Magento 2,PHP