Skip to content

Commit

Permalink
Fixed file upload in Magento 2.4.5+
Browse files Browse the repository at this point in the history
  • Loading branch information
roma84 committed May 26, 2023
1 parent b7f56e6 commit 4b15a70
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Controller/Index/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ public function execute()
TestimonialsModel:: STATUS_AWAITING_APPROVAL;
$model = $this->testimonialsFactory->create();
$model->setData($post);
if (isset($post['image'])) {
if ($image = $this->getRequest()->getFiles('image')) {
$imageName = $this->uploadModel
->uploadFileAndGetName('image',
$this->imageModel->getBaseDir(),
$post,
$image,
['jpg','jpeg','gif','png', 'bmp']
);
$model->setImage($imageName);
Expand Down
6 changes: 3 additions & 3 deletions Model/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(UploaderFactory $uploaderFactory)
public function uploadFileAndGetName($input, $destinationFolder, $data, $allowedExtensions = [])
{
try {
if (isset($data[$input]['delete'])) {
if (isset($data['delete'])) {
return '';
} else {
$uploader = $this->uploaderFactory->create(['fileId' => $input]);
Expand All @@ -48,8 +48,8 @@ public function uploadFileAndGetName($input, $destinationFolder, $data, $allowed
if ($e->getCode() != Uploader::TMP_NAME_EMPTY) {
throw new \Exception($e->getMessage());
} else {
if (isset($data[$input]['value'])) {
return $data[$input]['value'];
if (isset($data['value'])) {
return $data['value'];
}
}
}
Expand Down

0 comments on commit 4b15a70

Please sign in to comment.