Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $baseTmpPath = $this->getBaseTmpPath();
- $uploader = $this->uploaderFactory->create(['fileId' => $fileId]);
- $uploader->setAllowedExtensions($this->getAllowedExtensions());
- $uploader->setAllowRenameFiles(true);
- $result = $uploader->save($this->varDirectory->getAbsolutePath($baseTmpPath));
- $true = true;
- $false = false;
- if (isset($result['name'])) {
- $fileNameComplete = $result['name'];
- $name = explode("_", $fileNameComplete);
- $prefix = preg_match('/product-import/',$name[0]);
- $fileName = preg_match('/[0-9]/',$name[1]);
- $counter = preg_match('/[0-9]/',$name[2]);
- if ($prefix == 1 && $fileName == 1 && $counter == 1 ) {
- $result['tmp_name'] = str_replace('\\', '/', $result['tmp_name']);
- $result['path'] = str_replace('\\', '/', $result['path']);
- $result['url'] = $this->storeManager
- ->getStore()
- ->getBaseUrl(
- \Magento\Framework\UrlInterface::URL_TYPE_MEDIA
- ) . $this->getFilePath($baseTmpPath, $result['file']);
- $result['name'] = $result['file'];
- if (isset($result['file'])) {
- try {
- $relativePath = rtrim($baseTmpPath, '/') . '/' . ltrim($result['file'], '/');
- $this->coreFileStorageDatabase->saveFile($relativePath);
- } catch (\Exception $e) {
- $this->logger->critical($e);
- throw new \Magento\Framework\Exception\LocalizedException(
- __('Something went wrong while saving the file(s).')
- );
- }
- }
- } else{
- return $false;
- }
- }
- return $true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement