Код: Выделить всё
$.each(previousFiles, function(index, file) {
const fileExtension = file.name.split('.').pop().toLowerCase();
if (!allowedExtensions.includes(fileExtension)) {
alert('Only JPG and PNG files are allowed.');
return;
}
};
Код: Выделить всё
$filePath = $uploadPath . $newName;
$fileExtension = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
if (!in_array($fileExtension, ['jpeg', 'jpg', 'png'])) {
return $this->response->setJSON([
'success' => false,
'message' => 'Only JPG and PNG files are allowed.'
]);
}
Я пробовал использовать этот код
Код: Выделить всё
$.each(previousFiles, function(index, file) {
const fileExtension = file.name.split('.').pop().toLowerCase();
if (!allowedExtensions.includes(fileExtension)) {
alert('Only JPG and PNG files are allowed.');
return;
}
};
Код: Выделить всё
$filePath = $uploadPath . $newName;
$fileExtension = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
if (!in_array($fileExtension, ['jpeg', 'jpg', 'png'])) {
return $this->response->setJSON([
'success' => false,
'message' => 'Only JPG and PNG files are allowed.'
]);
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... -extension