diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index fba82ded51..0c48e00e8a 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -10,6 +10,7 @@ use PhpMyAdmin\Charsets; use PhpMyAdmin\Charsets\Charset; use PhpMyAdmin\Core; use PhpMyAdmin\Encoding; +use PhpMyAdmin\FileListing; use PhpMyAdmin\Message; use PhpMyAdmin\Plugins; use PhpMyAdmin\Plugins\ImportPlugin; @@ -120,6 +121,38 @@ class Import 'can_convert_kanji' => Encoding::canConvertKanji(), 'charsets' => $charsets, 'is_foreign_key_check' => Util::isForeignKeyCheck(), + 'user_upload_dir' => Util::userDir($cfg['UploadDir'] ?? ''), + 'local_files' => self::getLocalFiles($importList), ]); } + + /** + * @param array $importList List of plugin instances. + * + * @return false|string + */ + private static function getLocalFiles(array $importList) + { + $fileListing = new FileListing(); + + $extensions = ''; + foreach ($importList as $importPlugin) { + if (! empty($extensions)) { + $extensions .= '|'; + } + $extensions .= $importPlugin->getProperties()->getExtension(); + } + + $matcher = '@\.(' . $extensions . ')(\.(' . $fileListing->supportedDecompressions() . '))?$@'; + + $active = isset($GLOBALS['timeout_passed'], $GLOBALS['local_import_file']) && $GLOBALS['timeout_passed'] + ? $GLOBALS['local_import_file'] + : ''; + + return $fileListing->getFileSelectOptions( + Util::userDir($GLOBALS['cfg']['UploadDir'] ?? ''), + $matcher, + $active + ); + } } diff --git a/libraries/classes/Html/Forms/Fields/DropDownUploadFileBlock.php b/libraries/classes/Html/Forms/Fields/DropDownUploadFileBlock.php deleted file mode 100644 index b7f06ed383..0000000000 --- a/libraries/classes/Html/Forms/Fields/DropDownUploadFileBlock.php +++ /dev/null @@ -1,81 +0,0 @@ -' - . sprintf( - __('Select from the web server upload directory %s:'), - htmlspecialchars(Util::userDir($uploaddir)) - ) - . ''; - - $extensions = ''; - foreach ($import_list as $import_plugin) { - if (! empty($extensions)) { - $extensions .= '|'; - } - $extensions .= $import_plugin->getProperties() - ->getExtension(); - } - - $matcher = '@\.(' . $extensions . ')(\.(' - . $fileListing->supportedDecompressions() . '))?$@'; - - $active = isset($GLOBALS['timeout_passed'], $GLOBALS['local_import_file']) && $GLOBALS['timeout_passed'] - ? $GLOBALS['local_import_file'] - : ''; - - $files = $fileListing->getFileSelectOptions( - Util::userDir($uploaddir), - $matcher, - $active - ); - - if ($files === false) { - Message::error( - __('The directory you set for upload work cannot be reached.') - ) - ->display(); - } elseif (! empty($files)) { - $block_html .= "\n" - . ' ' . "\n"; - } elseif (empty($files)) { - $block_html .= '' . __('There are no files to upload!') . ''; - } - - return $block_html; - } -} diff --git a/libraries/classes/Html/Forms/Fields/FieldGenerator.php b/libraries/classes/Html/Forms/Fields/FieldGenerator.php deleted file mode 100644 index 786a8b523f..0000000000 --- a/libraries/classes/Html/Forms/Fields/FieldGenerator.php +++ /dev/null @@ -1,14 +0,0 @@ - ['html']] ), - new TwigFunction( - 'get_select_upload_file_block', - '\PhpMyAdmin\Html\Forms\Fields\DropDownUploadFileBlock::generate', - ['is_safe' => ['html']] - ), new TwigFunction( 'get_start_and_number_of_rows_panel', 'PhpMyAdmin\Html\Generator::getStartAndNumberOfRowsPanel', diff --git a/templates/display/import/import.twig b/templates/display/import/import.twig index e248f14806..0f9530613a 100644 --- a/templates/display/import/import.twig +++ b/templates/display/import/import.twig @@ -79,14 +79,22 @@
{% trans 'You may also drag and drop a file on any page.' %}
{% trans 'You may also drag and drop a file on any page.' %}
- {% elseif not is_upload %} - {{ 'File uploads are not allowed on this server.'|trans|notice }} {% elseif upload_dir is not empty %} - {{ get_select_upload_file_block( - import_list, - upload_dir - ) }} + + + {% if local_files is same as(false) %} + {{ 'The directory you set for upload work cannot be reached.'|trans|error }} + {% elseif local_files is not empty %} + + {% else %} + {% trans 'There are no files to upload!' %} + {% endif %} + {% else %} + {{ 'File uploads are not allowed on this server.'|trans|notice }} {% endif %}