Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. $baseTmpPath = $this->getBaseTmpPath();
  2. $uploader = $this->uploaderFactory->create(['fileId' => $fileId]);
  3. $uploader->setAllowedExtensions($this->getAllowedExtensions());
  4. $uploader->setAllowRenameFiles(true);
  5. $result = $uploader->save($this->varDirectory->getAbsolutePath($baseTmpPath));
  6. $true = true;
  7. $false = false;
  8. if (isset($result['name'])) {
  9.  
  10. $fileNameComplete = $result['name'];
  11. $name = explode("_", $fileNameComplete);
  12.  
  13. $prefix = preg_match('/product-import/',$name[0]);
  14. $fileName = preg_match('/[0-9]/',$name[1]);
  15. $counter = preg_match('/[0-9]/',$name[2]);
  16.  
  17. if ($prefix == 1 && $fileName == 1 && $counter == 1 ) {
  18.  
  19. $result['tmp_name'] = str_replace('\\', '/', $result['tmp_name']);
  20. $result['path'] = str_replace('\\', '/', $result['path']);
  21. $result['url'] = $this->storeManager
  22. ->getStore()
  23. ->getBaseUrl(
  24. \Magento\Framework\UrlInterface::URL_TYPE_MEDIA
  25. ) . $this->getFilePath($baseTmpPath, $result['file']);
  26. $result['name'] = $result['file'];
  27. if (isset($result['file'])) {
  28. try {
  29. $relativePath = rtrim($baseTmpPath, '/') . '/' . ltrim($result['file'], '/');
  30. $this->coreFileStorageDatabase->saveFile($relativePath);
  31. } catch (\Exception $e) {
  32. $this->logger->critical($e);
  33. throw new \Magento\Framework\Exception\LocalizedException(
  34. __('Something went wrong while saving the file(s).')
  35. );
  36. }
  37. }
  38. } else{
  39. return $false;
  40. }
  41. }
  42. return $true;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement