Fix PHP error happening when uploading file without extension if the JS dropzone uploader is configured to allow empty file extensions

This commit is contained in:
Flavio Copes
2016-01-16 18:49:42 +01:00
parent f068b48fce
commit 08135ee843

View File

@@ -628,15 +628,18 @@ class AdminController
// Check extension
$fileParts = pathinfo($_FILES['file']['name']);
$fileExt = strtolower($fileParts['extension']);
$fileExt = '';
if (isset($fileParts['extension'])) {
$fileExt = strtolower($fileParts['extension']);
}
// If not a supported type, return
if (!$config->get("media.{$fileExt}")) {
if (!$fileExt || !$config->get("media.{$fileExt}")) {
$this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.UNSUPPORTED_FILE_TYPE') . ': '.$fileExt];
return;
}
// Upload it
if (!move_uploaded_file($_FILES['file']['tmp_name'], sprintf('%s/%s', $page->path(), $_FILES['file']['name']))) {
$this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.FAILED_TO_MOVE_UPLOADED_FILE')];