Merge pull request #1643 from Azhar-Webkul/gli-2964
Fixed : Issue while uploading images in hotel reviews in front-office.
This commit is contained in:
@@ -290,9 +290,13 @@ class QhrHotelReview extends ObjectModel
|
||||
public function saveReviewImages()
|
||||
{
|
||||
$files = QhrHotelReviewHelper::fileAttachmentMultiple('images');
|
||||
$allowedExtensions = array('jpg', 'png', 'jpeg',);
|
||||
if (is_array($files) && count($files)) {
|
||||
foreach ($files as $key => $file) {
|
||||
$ext = pathinfo($file['rename'], PATHINFO_EXTENSION);
|
||||
if (!in_array($ext, $allowedExtensions, true)) {
|
||||
continue;
|
||||
}
|
||||
$dir = _PS_MODULE_DIR_.'qlohotelreview/views/img/review/'.Image::getImgFolderStatic($this->id);
|
||||
QhrHotelReviewHelper::createDirectory($dir);
|
||||
$useSameExt = false;
|
||||
|
||||
@@ -85,6 +85,17 @@ class QloHotelReviewDefaultModuleFrontController extends ModuleFrontController
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($_FILES) && array_key_exists('images', $_FILES) ) {
|
||||
$allowedExtensions = array('jpg', 'png', 'jpeg',);
|
||||
foreach ($_FILES['images']['name'] as $key => $imageName) {
|
||||
$extension = Tools::strtolower(pathinfo($imageName, PATHINFO_EXTENSION));
|
||||
if (!in_array($extension, $allowedExtensions)) {
|
||||
$errors['general'][] = $objModule->l('Only images with the following extensions are allowed: jpg, jpeg, png','default');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!count($errors['by_key']) && !count($errors['general'])) {
|
||||
$customerReview = QhrHotelReview::getByCustomer(
|
||||
$objOrder->id_customer,
|
||||
|
||||
@@ -182,6 +182,7 @@ class QloHotelReview extends Module
|
||||
$this->l('You can upload a maximum of %d images.', false, true),
|
||||
(int) Configuration::get('QHR_MAX_IMAGES_PER_REVIEW')
|
||||
),
|
||||
'allowed_extensions' => $this->l('Only images with the following extensions are allowed: jpg, jpeg, png', false, true),
|
||||
),
|
||||
)));
|
||||
|
||||
|
||||
@@ -52,6 +52,10 @@
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
#add-review-popup .hint {
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
#add-review-popup .review-error {
|
||||
margin-top: 2px;
|
||||
color: #E85757;
|
||||
|
||||
@@ -132,6 +132,29 @@ var QhrReviewImages = {
|
||||
init: function() {
|
||||
QhrReviewImages.inputHtml = '<input type="file" accept="image/*" class="input-images hidden" name="images[]" multiple>';
|
||||
},
|
||||
validateFiles: function () {
|
||||
$('#review-general-errors').hide();
|
||||
let isValid = true;
|
||||
$('.images-field input.input-images').each(function (iInput, input) {
|
||||
let files = input.files;
|
||||
let dataTransfer = new DataTransfer();
|
||||
$.each(files, function (iFile, file) {
|
||||
if (file.type.startsWith('image/')) {
|
||||
dataTransfer.items.add(file);
|
||||
} else {
|
||||
isValid = false;
|
||||
}
|
||||
});
|
||||
input.files = dataTransfer.files;
|
||||
if (!input.files.length) {
|
||||
$(input).remove();
|
||||
}
|
||||
});
|
||||
if (!isValid) {
|
||||
QhrReviewForm.showGeneralErrors(qlo_hotel_review_js_vars.texts.allowed_extensions);
|
||||
}
|
||||
return isValid;
|
||||
},
|
||||
getFilesCount: function() {
|
||||
var count = 0;
|
||||
$('.images-field input.input-images').each(function(i, input) {
|
||||
@@ -156,6 +179,9 @@ var QhrReviewImages = {
|
||||
}
|
||||
});
|
||||
input.files = dataTransfer.files;
|
||||
if (input.files.length === 0) {
|
||||
$(input).remove();
|
||||
}
|
||||
},
|
||||
resetPreviews: function() {
|
||||
$('.previews-wrap').html('');
|
||||
@@ -241,8 +267,9 @@ $(document).on('change', 'input.input-images', function(e) {
|
||||
var filesCount = QhrReviewImages.getFilesCount();
|
||||
if (filesCount > qlo_hotel_review_js_vars.num_images_max) {
|
||||
QhrReviewImages.removeLastInput();
|
||||
alert(qlo_hotel_review_js_vars.texts.num_files);
|
||||
QhrReviewForm.showGeneralErrors(qlo_hotel_review_js_vars.texts.num_files);
|
||||
} else {
|
||||
QhrReviewImages.validateFiles();
|
||||
QhrReviewImages.updatePreviews();
|
||||
|
||||
if (filesCount == qlo_hotel_review_js_vars.num_images_max) {
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
<div class="image-input-btn">
|
||||
<img class="img-camera-plus">
|
||||
</div>
|
||||
<p class="hint">{l s='Allowed formats are: .jpg, .jpeg, .png' mod='qlohotelreview'}</p>
|
||||
|
||||
<div class="previews-wrap"></div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user