Skip to content

Instantly share code, notes, and snippets.

@denvit
Last active May 28, 2024 10:17
Show Gist options
  • Save denvit/204c4947a324a88eb69509a000fcda5c to your computer and use it in GitHub Desktop.
Save denvit/204c4947a324a88eb69509a000fcda5c to your computer and use it in GitHub Desktop.
Magento 2 - move file
<?php
\Magento\Framework\Filesystem\Io\File $file
\Magento\Framework\App\Filesystem\DirectoryList $directoryList
/**
* @param array $files
* @throws \Magento\Framework\Exception\FileSystemException
*/
public function archiveFile(array $files)
{
$archivePath = $this->directoryList->getPath('var') . '/import/archive/';
if (!is_dir($archivePath)) {
mkdir($archivePath, 0775);
}
if (is_array($files) && count($files) > 0) {
foreach ($files as $filepath) {
$fileName = pathinfo($filepath);
$this->file->mv($filepath, $archivePath . $fileName['basename']);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment