Last active
May 28, 2024 10:17
-
-
Save denvit/204c4947a324a88eb69509a000fcda5c to your computer and use it in GitHub Desktop.
Magento 2 - move file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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